Table of Contents
站点主页
maliang 3.1.x¶
字数 256 个 代码 3 行 阅读时间 1 分钟 访问量
温馨提示
这里是 maliang 3.1.x 系列版本的教程和文档网站,请走错的朋友在网页左上角切换版本哈……😅
- 您可以通过按下快捷键 Left 和 Right 来快速跳转到上一页和下一页!🎉
- 您可以通过点击页面顶部搜索栏或按下快捷键 / 来快速查找想要的内容!✨
- 您可以通过点击页面顶部主题按钮来切换网站主题,不同主题带来不同的心情!🎨
- 您可以在阅读教程和查阅文档的时候,点击顶部的音乐播放器享受一下作者精选的纯音乐,自动循环播放!🎈
- 您可以在大部分的页面底部找到评论区,登录 GitHub 账号之后就可以公开发表您的想法!👀
最后,祝您阅读愉快!❤️
本站最后更新(构建)时间:2025-10-23 01:05:04 +0800
标签索引¶
字数 4 个 阅读时间不到 1 分钟 访问量
tags.md:266-288/name¶
官方教程
官方教程¶
字数 1205 个 代码 8 行 图片 2 张 阅读时间 4 分钟 访问量
特别注意:教程版本要求
目前此教程对应的环境如下(文档构建时自动更新):
- maliang:
3.1.5 - Python:
3.13.9 - OS:
Windows
若您需要的教程不是该版本,请在网页左上切换版本!
特别提供:相关教程及文档链接
- Tcl / Tk 8.6 官方文档:www.tcl.tk/man/tcl8.6/contents.htm
- Tcl / Tk 9.0 官方文档:www.tcl.tk/man/tcl9.0/
- 个人不完整 Tk 参考教程:xiaokang2022.blog.csdn.net/category_11600888.html
- 个人推荐的 Tk 参考教程:blog.csdn.net/qq_41556318/category_9283243.html
一、阅前须知¶
1.1 主题说明*¶
此网站主题默认跟随系统,可手动调节为暗色主题或者亮色主题,这不仅会影响网站的颜色外观,更会影响部分在不同主题下的图片,因为 maliang 涉及亮色和暗色主题,所以部分效果预览图也会同步受网站主题而切换。
例如,下面的 “图1 在 VSCode 中查看类的文档字符串” 就受网站主题影响,大家可以试着在页面顶部切换网站主题颜色,看看这张图片有什么变化。
此外,本站的所有图片都可以通过点击来放大。
1.2 图像说明*¶
图形分为两种,一种是由图片文件直接展示的,还有一种是由 Markdown 的 Mermaid 语法代码块生成的。某些时候这些图没有完全生成,而是呈现出一种源代码的状态,此时可以尝试刷新网页重新让它们生成。
另外,它们的颜色也与主题有关。
1.3 前置需求¶
推荐在阅读此教程的同时搭配 Visual Studio Code(以下简称 VSCode)进行开发,使用 PyCharm 或者 Visual Studio 也可以,但我个人更推荐使用 VSCode。
maliang 3(以下简称 maliang) 专门对 VSCode 做了文档字符串的优化,可以十分方便地在 VSCode 内看到每个函数、类甚至是常量的详细信息,包括它们的类型、默认值和使用方法。只需要将鼠标移动到想要查看的函数或者类上面即可,PyCharm 和 Visual Studio 也有类似的功能,但渲染效果不如 VSCode 的那么好。虽然可以直接查看文档字符串,但 maliang 在开发的时候为了力求符合 PEP 8 的规则,所以文档字符串均是英文的。阅读起来不方便的朋友们可以在本站查阅教程来进行辅助开发。
图 1 在 VSCode 中查看类的文档字符串
二、想说的一些事情¶
2.1 关于该项目名字的由来¶
实际上,该项目的旧版本并不叫 maliang,而是 tkintertools。这是因为在以前本项目还没有做得这么大的时候,本项目只是一个用来辅助 tkinter 进行开发的工具,所以取名为 tkinter 和 tools 的结合,但这个名称将止步于 3.0.0 版本,在这个版本发布前,经过社区投票,我决定更改这个项目的名称,并最终取名为 maliang。
至于为什么要起这个名字,实际和本项目的最终目标有一定联系,不知大家小时候有没有用画板画程序界面的这种想法?有些人不仅想过,还实际做过,比如我。小时候看着花花绿绿的电脑屏幕,不会编程的我只能用 “画图.exe” 在上面画一些自己幻想的程序,觉得非常好玩。是的,这很好玩,但这并不是真的界面,只是一副可能算不上画的画罢了。但“神笔马良”的故事大家都知道,马良有一支神笔,能让画出来的东西变成真的!要是有这么一个项目,真的能让画出来的界面变成真的,岂不美哉?
是的,你想的没错,通过画画来构建图形界面就是这个项目的终极目标。因此,该项目被重命名为了 maliang。这个时候就有人要问了,你这怎么只有“马良”,你的“神笔”呢?别急!“神笔”也是有的,本项目只是一个 UI 框架,但还需一个配套的可视化开发软件,而这个软件就是“神笔”,目前“神笔”项目还处于初期阶段,只能实现控件的拖拽,但随着不断的开发,它的功能将越来越强大。
“神笔”项目也是开源的,项目链接为:Xiaokang2022/Magic-Brush
2.2 养成看教程和文档的好习惯¶
教程和文档是最好的资源,实时更新和维护,尽可能保证准确性,养成看教程和文档的好习惯会让你的开发事半功倍。
所以不要有事没事儿就问我这问我那,以及在评论区问东问西(bushi
第一章:安装与初识
第一章:安装与初识¶
字数 114 个 图片 2 张 阅读时间不到 1 分钟 访问量
章节概述
本章不会深入介绍如何使用 maliang 来构建一个图形化的程序,但会介绍如何安装 maliang 并通过简单的示例来展示构建一个图形化程序的过程。
同时会简要地介绍一下 maliang 的框架,方便各位理解 maliang。
本章内容¶
§1.1 环境搭建¶
字数 722 个 代码 19 行 图片 7 张 阅读时间 3 分钟 访问量
一、环境要求¶
maliang 运行要求 Python 版本大于等于 3.10,操作系统没有过多要求(Windows、macOS、Linux 均可)。(1)
- 💡但实际上我更推荐使用 Windows 操作系统
推荐使用 Python 3.11 及以上版本。
二、安装 maliang¶
2.1 纯净安装¶
maliang 目前的依赖包只有 Python 官方的 python/typing_extensions,安装时会自动安装依赖:
2.2 完整安装¶
若想获取 maliang 的完整功能,用如下命令进行安装:
上述命令的第一条是安装 maliang 及其全部的可选依赖包,第二条命令是安装 maliang 的官方扩展包。
所有的可选依赖包信息如下:
- albertosottile/darkdetect: 提供操作系统主题检测
- python-pillow/Pillow: 提供更多类型图片的使用及优化图片缩放速度
- Akascape/py-window-styles: 提供一些 Windows 系统的窗口效果
- Zingzy/hPyT: 提供更多 Windows 系统窗口的配置选项
- littlewhitecloud/win32material: 提供更多 Windows 系统窗口的配置选项
所有的官方扩展包信息如下:
- Xiaokang2022/maliang-mpl: 提供
matplotlib包的相关支持 - Xiaokang2022/maliang-media: 提供媒体文件的相关支持
- Xiaokang2022/maliang-three: 提供简单 3D 绘图的相关支持
- Xiaokang2022/maliang-table: 提供表格控件的相关支持
如果您只想安装上述的部分包,可以单独使用 pip 进行安装。
2.3 推荐安装¶
以下是安装命令:
maliang 目前所必须安装的依赖包只有上面提到的一个,它只是用来强化类型提示的,但为了您的良好体验,建议安装推荐的可选依赖包,即用 pip 安装时加上上述命令的 “opt” 字段。
2.4 升级安装¶
如果您之前安装过 maliang,但并不是最新版本,您可以通过以下命令进行升级:
当然,如果需要同步升级可选包或者扩展包,你可能需要下面的命令:
2.5 检验安装¶
运行以下代码来检验 maliang 是否安装成功:
若运行无误,则可以在终端输出中看到当前 maliang 的版本。
三、体验最新功能¶
有些功能可能并未存在于当前最新版的 maliang 中,这就需要下载安装最新提交的版本,其安装方式并不是直接同 PyPI 上下载,而是克隆存储库后再下载的。
下面是安装命令:
-
当然,你也可以这样写
或者
另附:如果无法访问 GitHub,可使用镜像源同名仓库的地址:(1)
- 镜像源数据一般会在 24 小时内同步,可能更新不及时,一切以 GitHub 的数据为准!
- Gitee(首选镜像源):
- GitCode:
§1.2 实现一个简单的界面¶
字数 568 个 代码 33 行 图片 4 张 阅读时间 2 分钟 访问量
本节不对 maliang 的具体使用做详细讲解,这里只是给大家提供一个简单程序体验一下 maliang。
以最简单的登录窗口为例,说明一下使用 maliang 搭建图形界面的流程是怎样的。
一、登录窗口¶
1.1 构建窗口¶
运行以下命令以构建一个标题为 “登录” 并且居中窗口
maliang 是支持暗色模式的,如果您装有 darkdetect 可选依赖包,则 maliang 不仅仅会将界面渲染成暗色,窗口也会更改为暗色模式。
特别注意:窗口的暗色模式可能不生效
窗口本身的暗色模式在部分操作系统上可能不会生效(如部分 Linux 系统),但窗口内部的控件等的暗色模式是可以修改的。关于窗口的暗色模式,模式的检测与第三方包 albertosottile/darkdetect 有关,模式的支持与操作系统及相关第三方包有关,下面是对应关系:
- Windows: Akascape/py-window-styles
- Linux: 暂不支持手动修改
- macOS: 暂不支持手动修改
1.2 创建画布¶
maliang 的宗旨就是,一切都是通过画布“画”出来的,你可以把画布当作网页的页面,每一页就是一个画布实例。使用 Canvas 来创建画布。
1.3 创建控件¶
创建一些控件来实现登录窗口。
这样就完成了一个没有功能的登录界面。你可以在此时尝试着更改操作系统颜色模式,看看该窗口的颜色模式会不会跟随改变。(1)
- 💡你也可以在页面顶栏试着切换网站的主题(点击图标 来切换),看看不同主题下程序运行的效果
图 1 教程环境下的运行结果
§1.3 框架概述¶
字数 1516 个 阅读时间 5 分钟 访问量
一、起因¶
1.1 为什么要写 maliang¶
Python 在图形化程序的开发上除了可以选择内置的 tkinter 之外,实际还有很多优秀的第三方包来支持,如 PySide、PyQT、wxpython 等等,但为什么我还要开发 maliang 呢?
实际上,最开始写 maliang 的目的并非是要构建什么框架,而只是作为一个辅助工具,辅助我自己开发图形化的程序,这在前面也已经讲过了,但随着量的逐渐增加,maliang 也变得像个样子了,于是我的目标不再只是将其作为一个辅助工具,而是作为一个简易的 UI 框架,在帮我实现某些功能的同时,开源出来,让大家一起使用,一起开发。
1.2 为什么选择 tkinter 作为底层¶
你其实可以想一下,Python 已是当今世界上最流行的编程语言了,既然它如此流行,为什么还会选择 tkinter 作为内置的图形化接口呢?
很多人都说 tkinter 丑陋、落后以及性能低下,Python 官方将其内置只是因为它的语法简单。诶嘿,这“语法简单”就很关键了!众所周知,Python 的简单易用就是其出色的特点之一,因此选择同样简单的图形库就非常合理了。当然,这些其实都只是大家的猜测,官方不一定是这样想的。
个人认为,tkinter 的底层,Tk/Tcl 涉及到很多的东西,官方无法将其弃置,所以才会一直选用它。首先,Tk/Tcl 非常小,在 UI 框架里面属于极其轻量级的,此外它跨平台、开源、免费、易用、兼容性非常好,很多库和小工具都与其做了对接。比如使用量最大的开源轻量级数据库 SQLite 就有对 Tcl 的对接,而正好 Python 有个内置库 sqlite3 实现了 SQLite 的接口。
此外,Python 还有多个内置库都使用了 tkinter,如以教育方面著名内置库 turtle 就是以 tkinter 为底层的,还有内置库 idlelib 实现了 Python 打开即用的集成开发环境 IDLE,其底层也是 tkinter。
这些还是内置库的,第三方库也有不少做了与 tkinter 的对接,如 matplotlib、pillow 等。
所以,为什么选择 tkinter 作为 maliang 的底层,原因就很简单了。
二、设计目标¶
2.1 目标由来¶
说完起因了,就该说说 maliang 的预期目标了。既然要开发一个 UI 框架,就难免不和其它成熟的 UI 框架去做比较,既然要比较,那就必须要有优势才行。
截至 tkintertools 2(maliang 的前代版本),目标都不是以 UI 框架去定义的,从 maliang 开始,才真正地向着一个 UI 框架走。maliang 起初是一个辅助工具,因此它就应该从以前版本的开始,具备一些弥补 tkinter 缺点的功能,于是目标很简单,把 tkinter 很难做的功能给实现出来,并将其封装好,提供简单易用的接口给用户使用。
这一目标和一开源 UI 框架 TomSchimansky/CustomTkinter 很像。从名字上来看,customtkinter 可以高度自定义你的 tkinter 程序,maliang 的目标也是如此,但这还不够。因为再怎么样,customtkinter 的控件都无法脱离 tkinter 的真实控件,这就导致控件数量十分有限,那么该怎么解决这个问题呢?
2.2 主体思路¶
其实,无论任何控件,其归根结底,都是在计算机屏幕上绘制出来的,那些 UI 效果无非就是对绘制出来的图形和颜色加以控制罢了。试想完全把整个窗口当成一个画布,而 UI 就是在上面画画而已。于是,maliang 的开发主体思路就定下来了,就是用 tkinter.Canvas 对象来当做窗口,而用户要做的就是在上面“画” UI!
由于一切都是通过画布绘制的,因此理论上可以实现任何控件,限制各位开发者的不再是底层和平台,而是大家的想象力!
三、基本框架¶
3.1 控件构建框架¶
maliang 的构建控件基本框架如下图所示:
flowchart LR
app{{ APP }}
tk(Tk)
tp1(Toplevel 1)
tp2(Toplevel 2)
cv1(Canvas 1)
cv2(Canvas 2)
wid1([Widget 1])
wid2([Widget 2])
wid3([Widget 3])
cp1([Element 1])
cp2([Element 2])
it1[Item 1]
it2[Item 2]
_1(More...)
_2([More...])
_3([More...])
_4[More...]
_5(More...)
app --> tp1; app --> tp2; app --> tk; app --> _5;
tk --> cv1; tk --> cv2; tk --> _1;
cv2 --> wid1; cv2 --> wid2; cv2 --> _2;
wid2 --> cp1; wid2 --> cp2; wid2 --> _3; wid2 --> wid3;
cp2 --> it1; cp2 --> it2; cp2 --> _4;
其中圆角矩形包起来的是从 tkinter 中继承而来的对象,半圆矩形的是 maliang 中定义的对象,矩形的是一个特殊对象,即画布元素,在 Python 中体现为一个 int 类型。
这里的控件(Widget)基本可以认为是 tkinter.Widget,但此处的元素(Element)或许需要我解释一下。简单说就是,控件的外观是由这些元素及控件组成的,而元素又是可以细分的,即:
flowchart TB
1[Element]
2([Text])
3([Image])
4([Shape])
5[Feature]
6[Widget]
7[Widget]
8[Style]
1 --> 2; 1 --> 3; 1 --> 4;
7 --> 6; 7 --> 5; 7 --> 8; 7 --> 1;
特别说明,这里的 Feature 是功能基类,是用来控制控件的功能的,Style 是样式基类,是用来控制控件的样式的。此外,这里的 Text、Image 和 Shape 都是基类,它们下面还有很多细分的类。
3.2 细节处理¶
上面都是在类级别的框架,在元素抽象基类下还可以细分,如 Shape,可以像下面这样构成:
flowchart TB
1([Shape])
2[line]
3[oval]
4[rectangle]
5[polygon]
6[More...]
1 --> 2; 1 --> 3; 1 --> 4; 1 --> 5; 1 --> 6;
上述的这些 line、oval 并不是类,而是画布的特殊对象(Item),以 int 的形式的存在(上文提到过)。
3.3 整体框架¶
上述两部分讲的都是控件的构建的框架,在 maliang 源代码中属于包 core(核心部分)和 standard(标准件) 的内容。除此之外,还有其它的一些包,如:
animation: 管理动画和控制器函数;color: 颜色处理;theme: 主题控制以及样式数据的解析和处理;toolbox: 提供一些实用的工具类和函数;
以及三个扩展包(需要通过额外的方式安装):
mpl: 实现和处理matplotlib相关的接口;media: 实现对带音频视频的播放;three: 实现简单的 3D 绘图;
总之,maliang 的整体功能极为丰富。
第二章:容器控件
第二章:容器控件¶
字数 66 个 图片 2 张 阅读时间不到 1 分钟 访问量
章节概述
本章会详细介绍容器控件的使用方式和需要注意的地方。
maliang 中的容器控件包括 Tk、Toplevel、Canvas。
本章内容¶
§2.1 窗口容器控件¶
字数 1597 个 代码 55 行 图片 2 张 阅读时间 6 分钟 访问量
一、容器控件¶
1.1 分类¶
容器控件一般分两类,一种是有实际窗口的控件,包括 Tk、Toplevel。另外一种则没有实际的窗口,是处于窗口之内的容器,如 Canvas。
1.2 主窗口¶
每个 tkinter 程序在运行期间一般只允许存在一个且必须存在一个主窗口(弹窗除外),即只有一个 Tk 类的实例。
主窗口也叫根窗口,所以我们常常能在 tkinter 程序的源代码中见到 “root” 字样,其含义就是根窗口的意思。你可以把图形化程序的搭建理解为一颗树,从根部搭起,后面的控件、组件都连着前面的,也就是有“子与父”的关系存在,没有父一般就没有子。
flowchart TB
1("Tk(root)")
2(Canvas 1)
3(Canvas 2)
4(Widget)
5(...)
1 --> 2; 3 --> 4;
1 --> 3; 3 --> 5;
1.3 子窗口¶
子窗口,或者叫顶级窗口(Toplevel),多用于额外的窗口,或者是自定义弹窗。
为什么叫顶级窗口呢,因为它和 Tk 一样有实际的窗口,处在“控件树”最顶端的位置,但其实际又属于 Tk 的“孩子”,根窗口一旦关闭,子窗口也会随之关闭,反之却不会。
二、窗口容器控件¶
2.1 Tk¶
2.1.1 循环刷新的主窗口¶
通过 Tk 来生成一个主窗口,生成该对象后,需要让其进入消息事件循环,而这个循环显然是一直运行的,直到主窗口对象生命周期的结束。
通过如下代码可以生成主窗口:
但我们运行上述代码可以发现,"Done!" 并没有被直接打印出来,而是当我们关闭窗口之后,这个 "Done!" 才被打印出来。这也说明,root.mainloop() 是一个类似于循环的操作,会让主窗口一直做一件事,也就是刷新窗口,直到窗口被关闭,这个循环才结束。
我们可以用下面近似等价的代码试验一下效果是不是一样的:
运行之后不难发现,当窗口打开 3 秒后会自动关闭,之后终端才输出 "Done!"。因此,写在 root.mainloop() 之后的代码一般是无效的。所以,这也从侧面说明,主窗口有且只有一个。
2.1.2 修改主窗口的属性¶
通过上面简单代码,我们已经可以创建出一个简单的窗口了,下面将讲述 Tk 有哪些内容可以修改,以及可以实现哪些效果。
首先,通过前面的章节 §1.3 框架概述,我们不难知道,Tk 是继承自 tkinter.Tk 的,因此 tkinter.Tk 的许多属性和方法是可以直接拿来用的,此处就不多讲了。这里专门讲一下 Tk 不同的地方吧。
通过查阅文档,我们可以通过初始参数设定主窗口的大小、位置、标题和图标。如下面代码可以创建一个大小为 1600×900(单位:像素),位置在距离屏幕左上角 100, 50,标题为 “My Window” 的窗口:
如果你不想计算窗口的位置,还可以通过 Tk 的方法 center 来居中窗口。
2.1.3 使用部分简化的语法¶
tkinter.Tk 有些很实用的功能可以使用,如全屏、置顶等,但它们使用调用起来比较麻烦,如使窗口置顶你需要这样写:
这不仅难记,而且容易出错,故 Tk 对这些功能做了一定的简化,如置顶只需要这样写:
与上面的类似的方法都写在这里了,具体参数和使用说明可以查阅文档:
- 通用:
alpha: 调节窗口透明度fullscreen: 设置窗口为全屏topmost: 设置窗口置顶
- 仅 Windows:
toolwindow: 设置窗口为工具窗口transparentcolor: 设置窗口的透明颜色
- 仅 macOS:
modified: 设置窗口的编辑状态transparent: 设置窗口是否启用透明功能
特别注意:部分功能不是跨平台的
并不是所有的功能都是跨平台的,如设置透明颜色的功能在部分 Linux 操作系统上可能就无法生效甚至报错!
因为并不是所有的操作系统都支持上述的这些方法,所以在使用的时候请特别注意。如果不确定哪些功能在哪些操作系统上会导致错误,请查阅 tkinter 相关文档。
2.1.4 创建后调整大小位置¶
可以使用方法 geometry 来调整窗口的位置和大小。
如果需要原生 tkinter 调整窗口位置和大小方法,可调用或者重载 wm_geometry 方法来使用,不过并不建议这样做,这样可能会导致缩放上的一些问题。
2.1.5 窗口关闭时调用函数¶
有时候,我们需要在窗口关闭的时候执行一些功能,比如询问用户文件是否需要保存等,这时可以使用 at_exit 方法。下面是一个简单的示例:
当窗口关闭的时候,程序会询问用户“是否关闭窗口”,若选择“是”则会关闭窗口,反之不会。
2.2 Toplevel¶
2.2.1 继承而来的子窗口类¶
Toplevel 是同时继承于 tkinter.Toplevel 和 Tk 的,所以 Tk 具有的方法,Toplevel 也有。
唯一不同的地方在于其初始化参数,详细说明可查阅文档。
2.2.2 居中窗口的小技巧¶
其实在仔细查阅了方法 center 的参数之后,不难发现,它有一个名为 master 的参数,当它的值为 None 的时候,居中的参考对象是屏幕,当它的值是根窗口的时候,就会以根窗口为参考对象而居中。
运行上面的代码,无论根窗口在哪里,子窗口始终会在其中间出现。
图 1 窗口居中
特别注意:居中并不是一定准确的
居中并不保证完全使窗口居中,因为这个窗口的范围判定并不一定和所看的外观一致。如 Windows7 风格的窗口在以 Windows10/11 窗口为参考对象居中时,看起来可能就不像是居中的。这可能与 tkinter 底层有关,tkinter 的 API 对 Windows7 风格的窗口给出结果貌似并不准确。
§2.1 画布容器控件¶
字数 1972 个 代码 73 行 阅读时间 7 分钟 访问量
一、以画布为底¶
1.1 为什么以画布为底¶
maliang 和 tkinter 程序不同,tkinter 程序是直接以窗口为底板,在上面放置控件的,但由于 maliang 的控件都是虚拟的,需要以画布为底板,在上面呈现出来。所以,在显示任何 maliang 控件之前,都需要一个画布来作为它们的容器。
1.2 将画布当作页面¶
我们可以把画布当作网页的一个个页面,每个画布都独立运作,这样层次就比较清晰,多个场景的切换也比较方便。
二、画布¶
2.1 Canvas¶
查阅文档可知,Canvas 继承自 tkinter.Canvas,它是在 tkinter.Canvas 的基础之上“魔改”而来的,增加了很多功能。
2.1.1 初始化参数的说明¶
直接查看文档可能还是不容易理解 Canvas 的初始化参数,这里做一个详细解释。
master: 父控件;expand: 这个可以取的值有 4 个,但实际含义就是画布本身的缩放的规则,"x"表示横向要缩放,"y"表示纵向要缩放,两个都有就表示横纵都缩放,空字符串则表示不缩放;auto_zoom: 布尔值,标志是否自动缩放画布里面的东西;keep_ratio: 可取值有"min","max"和None标志缩放保持比例的规则,"min"表示跟随最小的缩放比,"max"表示跟随最大的缩放比,None表示缩放不保持比例;free_anchor: 布尔值,标志画布的锚点是否为动态的;auto_update: 布尔值,标志着画布的样式是否自动根据主题而更新
这里着重讲一下后面两个参数。
保持画布横纵比例意味着画布里面的东西永远不会变形,这对于某些场景极为重要,比如播放视频,或者小游戏的画面。有两种模式,"min" 像播放视频那样,保证画面始终在父控件之中,而不会溢出画面,而 "max" 则是保证画面一定被铺满,就算某些部分会被父控件遮挡。
free_anchor 则涉及到画布缩放,且只对 Place 布局有效。它会使锚点位置的是动态缩放的,而不是一直位于某个地方。比如锚点位于画布左上角,初始位置在 (100, 100),假设缩放倍率为 2,那么当 free_anchor 的值为 True 时,锚点的位置会变成 (200, 200),反之则没有任何变化。
auto_update 为 True 时,maliang 的样式管理机制会自动根据窗口的主题修改画布的主题,也就是说,当它的值为 True 的时候,你无法修改画布的主题,就算通过某种手段修改了,当窗口主题发生变化时,画布的主题还是会自动更新。相对应地,如果你想自定义画布的样式,如背景颜色等,你可能需要将这个参数设为 False,此时画布的一切样式都会回归 tkinter 的默认值。当然,此时你可以自定义画布的主题:
上述代码可以让你的画布不受窗口主题变化的影响,但同样的,画布的外观细节都需要你自己设置。
2.1.2 隐藏/显示来切换页面¶
页面切换的方式有很多,你可以通过 tkinter 提供的方式,也可以通过 maliang 提供的方式。
当你使用 Place 布局时,在 tkinter 里面可以通过 place_forget 方法来将画布暂时隐藏掉。对于 Pack 和 Grid 布局也是类似的,可以使用 pack_forget 和 grid_forget 隐藏画布。但是当你想重新显示画布的时候,你必须再次使用对应的布局方法。而这个时候,你需要对当前窗口的缩放做出一定的处理。
如果窗口这个时候已经放大了,但你还是使用之前的方式去显示画布,就会导致画布看起来变小了。
下面是一个不正确的示例:
在上述程序开始运行后,用户可以快速缩放窗口,然后等待 3 秒,看看画布是否处于正确的大小。
很显然,上面的示例就会导致画布没有同步缩放。应该修改为如下代码:
- 更新画布,防止执行下一行的操作时画布的数据还没及时更新。
- 根据父控件和画布本身的数据重新调整画布的缩放。
此方法虽然可以,不过需要特别提醒的是,此方法仅对 Place 布局有效。
温馨提示:运行时动态创建控件需要调用控件的方法 zoom 来保证正确缩放
由于画布缩放后大小不一定和原来的一致,在缩放后创建新的控件就会导致新控件与其它控件的大小比例不协调,于是就需要缩放一下新创建的控件来保证比例协调。
通过调用控件的方法 zoom 来保证正确缩放,参数使用默认值即为自动适配画布的缩放比例。由于该操作有一定的性能开销,所以 maliang 并没有让所有的控件在创建时都自动调用该方法,开发者需要自己确定调用的时机以保证正确缩放。
2.1.3 动画移动来切换页面¶
当然除了上面说的这种方式之外,还有一种比较取巧的办法。那就是在程序开始的时候就把所有的画布一次性创建好,然后通过 Place 布局的方式将它们放置在看不到的位置,需要的时候就把他们移动到可见范围内,反之就移开。正好,maliang 提供了比较好的动画机制,可以试着用这种方式解决这个问题:
上述代码在运行 1 秒后,两个画布会有移动的动画。
特别注意:可能造成性能问题
对于上述第二种方式,在画布的数量较多时缩放窗口可能会产生性能问题。因为缩放机制会对当前所有“可见”的控件进行缩放(未第一次放置或者调用了类似 *_forget 方法的画布不可见),而这里的可见是指在程序层面可见的,故这种方式可能导致缩放时产生明显卡顿。
2.2 混合 tkinter 控件¶
画布可以承载 maliang 的虚拟控件,但它本身也是 tkinter 的控件,因此也可以包含 tkinter 的控件,这是完全可以的。
不过为了兼容性考虑,推荐在 Canvas 里的 tkinter 控件使用 Place 布局方式,这样在缩放时,其缩放模式会和 maliang 的虚拟控件保持一致。使用其它的布局方式也是可以,但无法保证缩放时能得到正确的结果。
上面代码就是在 Canvas 里混合了 tkinter 控件的示例。
运行这段代码,你可能会对这个效果很熟悉。其实在前面的章节 §1.2 实现一个简单的界面 的示例代码中我们已经用 maliang 实现了类似的效果,这里只是用 tkinter.ttk 再次实现了它,但不同的是,这里是 maliang 混合 tkinter.ttk 做的,其不仅具有 tkinter.ttk 的样式,还拥有了 maliang 的功能。(1)
- 💡你可以试着缩放窗口,看看与原生的
tkinter.ttk程序相比,有什么不同之处
2.4 嵌套画布¶
既然画布本身是 tkinter 控件,那自然画布可以嵌套在画布之中,当然,Canvas 和 Canvas 自身之间也是可以任意嵌套的。
第三章:基本控件
第三章:基本控件¶
字数 79 个 图片 2 张 阅读时间不到 1 分钟 访问量
章节概述
本章会详细说明如何使用 maliang 中所有的基本控件。
所有控件被分为三类:信息类控件、功能类控件和文本类控件。
本章内容¶
§3.1 信息类控件¶
字数 1496 个 代码 58 行 图片 20 张 阅读时间 6 分钟 访问量
温馨提示:切换网站主题可切换效果图的主题
本小节的图片大量涉及主题,你可以通过切换网站主题来查看在不同主题下程序运行的效果图,后面的章节也是一样的。网站的主题共有三种模式,分别对应 maliang 的主题三种模式。鼠标移至网站主题切换按钮下可查看当前主题。
一、信息类控件简述¶
1.1 什么是信息类控件¶
信息类控件就是指那些应该用于展示信息,而不具有额外功能的控件,如标签控件。
目前 maliang 内置的信息类控件有 Text、Image、Label、ProgressBar、Tooltip 和 Spinner。
1.2 注意事项¶
信息类控件的本意就是展示信息的,其不应该包含其他额外的功能,如果需要控件有其他的功能,应该考虑使用其他对应的控件或者自定义一个符合自己需要的控件。
关于自定义控件,后续章节中会详细讲述。
二、信息类控件详述¶
2.1 Text¶
Text 是文本控件,它的用途是展示一些文本。这些文本可以随着画布的缩放而缩放,随程序的亮色与暗色而改变。
我们可以使用其 get 和 set 方法来获取和设置控件所展示的文本内容。
下面这段代码会在坐标为 (10, 10) 的位置放置一个锚点为西北的文本,该文本的颜色会自动适应主题,同时可以响应画布的缩放。
效果如下:(1)
- 💡你可以通过更改网站主题来查看效果图在不同主题下的样子
2.2 Image¶
Image 是图片控件,用于展示图片,其可以响应画布的缩放,在没有安装 pillow 可选包的时候,仅支持 tkinter 原生图片格式(PNG 等),安装 pillow 之后可以支持更多的格式而无需更改任何代码。
特别注意:缺少 pillow 可能导致性能低下
在没有安装 pillow 的情况下,图片也是可以缩放的,但缩放的效率极低,极有可能导致窗口缩放时产生严重的卡顿,建议有图片缩放需求的朋友安装一下 pillow。
如果您已经按照 §1.1 安装 tkintertools 中的推荐方式安装,则不需要关心这则说明。
与上面提到的 Text 控件类似,我们也可以用 get和 set 方法来获取和设置 Image 控件的内容。
下面的代码是一个简单的示例:
效果如下:
示例中的图片文件是旧版 maliang 的 Logo,可以在此处获取。
maliang 的 Image 相比于 tkinter 的图片展示会稍微方便一些,对于 tkinter 展示图片的方法,其 PhotoImage 类有一个问题,其必须是全局变量(保持引用)才可以展示图片,详情见官方文档,而 maliang 的 Image 会对此进行一定的处理,使得某些情况不会出现“空白图片”的问题。
2.3 Label¶
maliang 的 Label 稍稍不同于 tkinter 的 Label,同样是展示信息,但 tkinter 的 Label 的功能更多的是用上面讲到的 Text 来替代的。这里的 Label 更像是标签真正的意义,也就是用它来展示一个类似于分类标签的东西,比如 GitHub Issue 的标签那样。
下面的代码是一个示例:
效果如下:
温馨提示:部分控件外观与系统相关
部分控件在不同的操作系统下有不同的外观,这是为了使控件更符合操作系统的 UI 风格,一般情况下,都会使用 Windows11 风格的。当然,你也可以强制指定一种风格,在后续章节中会提到这个的。
2.4 ProgressBar¶
ProgressBar 是进度条控件,相比于 tkinter 的进度条,maliang 的进度条在外观上有了很大的改善,但功能还不是完整的,缺少了无进度模式。
与前面提到的控件类似,我们可以使用 get 和 set 方法来获取和设置进度条的值,当设置的值小于 0 时被视为 0,大于 1 时被视为 1。
下面是一个简单的示例:
效果如下:
2.5 Tooltip¶
Tooltip 是工具提示框控件,简称提示框控件。它的作用就是在鼠标移至关联控件上面时显示出来以起到相应的提示作用。
特别注意:提示框无法跨画布显示
由于 maliang 的设计理念就是尽可能基于画布实现一切功能,所以提示框控件也是由画布绘制而成,无法跨出画布进行显示。
下面是一个简单的示例:
效果如下:
2.6 Spinner¶
Spinner 是环形进度条,类似于 ProgressBar,但它是环形的,且目前相比于 ProgressBar 它有两个模式:确定模式和不定模式。
- 确定模式(
"determinate"): 进度由用户控制,精确指定,表示加载进度确定的内容 - 不定模式(
"indeterminate"): 进度自动呈规律变化,表示正在加载但加载进度无法确定的内容
很显然,目前 ProgressBar 只有“确定模式”,而 Spinner 目前两种都支持。那为什么另外一个没有“不定模式”呢?因为我懒(bushi)
下面是个简单的示例:
效果如下:
§3.2 功能类控件¶
字数 1945 个 代码 111 行 图片 40 张 阅读时间 8 分钟 访问量
一、功能类控件简述¶
1.1 什么是功能类控件¶
从名字上就可以看出,它们是自带了一定功能的控件,相比于信息类控件,它们除了可以展示一定的信息之外,还可以通关相关互动改变相应的信息。
目前 maliang 内置的功能类控件有 Button、Switch、ToggleButton、CheckBox、RadioBox、UnderlineButton、HighlightButton、IconButton、Slider、SegmentedButton 和 OptionButton。
虽然看起来很多,但在后续章节中学习了自定义控件后,我们将会了解到实际上其中有很多的类都是大同小异的。
1.2 与信息类控件的差异¶
功能类控件与信息类控件最大的差异就是,其功能类 Feature 的复杂程度不同,有些信息类控件,如 Text 和 Image,甚至都没有功能类,也就是说,它们不具备任何交互。可以说,功能类控件的核心就是其功能类。
猜你想问:什么是功能类 Feature ?
在前面的选读章节 §1.3 框架概述 中有提到,maliang 的一个控件由五大基础部分组成,即 Shape、Image、Text、Style 和 Feature。它们分别负责图形部分、图像部分、文本部分、样式部分和功能部分。
二、功能类控件详述¶
下面的都是经典的基本控件,在各大 UI 框架都能见到它们的身影,而这里是 maliang 对它们的一个简单实现。
2.1 Button¶
Button 是按钮控件,可以用于执行某些函数。
下面是一个简单的示例,创建了一个文本内容为 "Button",且在点击后会在终端输出 "Click" 的按钮:
效果如下:
2.2 Switch¶
Switch 是开关控件,既可以直观地看到状态,又可以直接操作来改变状态。我们可以使用其 get 和 set 方法来获取和设置其状态。
下面的示例创建了两个开关控件,并给它们绑定了函数 print,当它被点击时会在终端输出当前的状态:
效果如下:
特别注意:default 参数和 set 方法
我们查阅文档可以注意到,开关控件包含一个名为 default 的初始化参数,可以设定其初始状态。于是我们可以使用两种方式来设置开关控件的初始状态,其一是利用 default 参数,其二是利用 set 方法。
若没有指定 set 方法的 callback 参数,那么这两种方式并没有差异。当 callback 被设置为 True,那么调用 set 方法的同时将调用控件绑定的关联函数,不管当前状态与设置的是否相同。反之,则只会改变控件的外观和状态,且仅在修改的状态与当前不同时执行。
后面有许多控件也有类似的设定,就不再赘述。
2.3 ToggleButton¶
ToggleButton 被称为开关按钮控件,它本质和上面的开关控件一样,只是外观不同罢了。
下面是一个简单的示例:
效果如下:
2.4 CheckBox¶
CheckBox 是复选框控件,但 maliang 的复选框控件可能和其它 UI 框架里面的复选框控件不同,其它的 UI 框架的复选框一般都是带文本的,但 maliang 的复选框真的就只有一个框。这样用户可以灵活放置复选框对应文本的位置。
下面的示例是复选框配上文本控件的效果:
效果如下:
2.5 RadioBox¶
与复选框控件对应的就是 RadioBox 单选框控件,与复选框控件类似,但是它的目前情况有些尴尬,因为无法判断哪些单选框是绑定在一起的,所以需要用户自己去绑定相关函数来完成单选框的功能。目前单选框只提供了一个外观,说简单点就是存在一定问题,有待优化。
下面是一个简单的示例:
-
实际上你也可以这样写:
效果如下:
如果觉得单选框这个不好操作,可以尝试选择使用功能类似的分段按钮控件。
2.6 Slider¶
Slider 滑动条控件,用于直观的调整处在某个范围的数据,并实时地看到反馈。
下面这个示例就可以在调节的同时在终端看到当前滑动条的值:
效果如下:
2.7 SegmentedButton¶
分段按钮控件,某些情况下可以作为单选框控件的平替。作用和单选框控件类似,只是外观不大相同,这里就不再赘述。
下面是一个简单的示例:
效果如下:
除了上面的示例代码演示的效果之外,我们还可以尝试设置分段按钮控件的其它参数,如将参数 layout 设置为 "vertical",你就可以得到一个纵向布局的分段按钮控件。
2.8 OptionButton¶
选项按钮控件,相当于折叠版的 SegmentedButton。它和 SegmentedButton 一样,只不过它的内容只有在点击按钮时才会展示出来,选择内容之后又会消失。
下面是一个简单的示例:
效果如下:
三、典型自定义控件¶
下面的这些控件属于对 Button 的一个二次修改得到的,属于简单自定义控件,比较典型,这里单独拿出来说明。
不过这里不会详述它们是怎么自定义出来的,只是在这里做一个分类,把它们当作和其它控件一样普通的控件就行。关于自定义控件,后续章节会做详细讲解。
特别注意:可能的变动
下面的这三个控件不属于基本的控件,在 maliang 正式版后可能会被移动到 maliang 控件扩展包!maliang 自身应只包括标准的基本控件,而非主流的控件应被单独成为一个包,以免过多不常用的控件的代码及其样式数据占用了空间。
3.1 UnderlineButton¶
此控件是为了实现网页链接那样的效果而做的,一般搭配文本控件来使用。
下面是一个简单的示例:
效果如下:
3.2 HighlightButton¶
此控件单纯只是自定义控件的一个演示,存在一定的问题,不过具有一定的参考意义。
下面是一个简单的示例:
效果如下:
3.3 IconButton¶
IconButton 是图标按钮控件,它本质上是一个便捷类,可以十分方便地将图标和文本融合到一个按钮里面。
下面是一个简单的示例,这个示例中使用到的图片仍是旧版 maliang 的 Logo,你也可以使用自己的图片文件:
效果如下:
§3.3 文本类控件¶
字数 945 个 代码 28 行 图片 12 张 阅读时间 4 分钟 访问量
一、文本类控件简述¶
1.1 什么是文本类控件¶
文本类控件就是功能主要与文本有关的一类控件,最典型的就是输入框控件了。由于涉及文本的相关功能多且复杂,因此 maliang 目前对文本类控件的支持还不是很好,某些功能还没有完全实现。
目前 maliang 内置的文本类控件有 InputBox、SpinBox 和 ComboBox。但这三个都是对于单行文本进行操作的控件,关于多行文本的控件,将在未来加入 maliang。
1.2 它们是如何运作的¶
其实,maliang 的文本类控件不像前面章节讲的那些控件一样,文本类控件实现起来非常复杂,为了遵循 maliang 一切都是绘制出来的宗旨以及实现某些特殊的功能,maliang 不得不做了妥协,借用 tkinter 中相对底层的 API 来“重绘”文本类控件,而不是直接使用 tkinter 的文本控件。
文本类控件需要实现大量功能,如复制、剪切、粘贴、文本选中、光标显示、文本显示、换行处理、字符替换等等,其中最复杂的莫过于文本的显示和选中了。我们知道一个输入框应该是有一定范围的,超出这个范围的字符是不会显示的,但 maliang 中的一切都是用画布绘制的,只能绘制,无法擦除,导致 maliang 无法像其它 UI 框架那样直接限制文本的范围来呈现出一种文本被切割的样子,maliang 只能通过控制字符显示的数量来达到类似的效果。而不同字符的宽度并不相同,更别说还要根据字体来计算,这就极大地增加了实现文本显示以及文本选中的功能的难度。
1.3 目前存在的缺陷¶
目前 maliang 对于文本类控件还是实现了一定的基本功能,但仍存在一些问题,如文本选中不完善,无法选中“框外隐藏”的文本,这一功能同时导致了全选功能只能选中显示出来的文本,而非真正的全选。不过在未来会实现这个功能的,目前只是暂时未实现而已。
二、文本类控件详述¶
2.1 InputBox¶
InputBox 就是输入框控件,是 tkinter 的控件 Entry 的平替,但相对 Entry 又有增强。我们可以通过设定其各个初始化参数来达到相应的要求,如通过设置参数 align 来设定文本的靠左、居中和靠右,设置参数 show 来替换原来显示的字符,设置参数 placeholder 来设定一个提示文本等。
下面是一个简单的示例,其设定一个提示文本,在控件内容为空且处于 "normal" 状态时,会以灰色显示这个提示文本:
效果如下:
2.2 SpinBox¶
从名称上就知道,这个控件对标的就是 tkinter 的 SpinBox 控件,功能类似的,不再赘述。
下面是一个简单的示例:
效果如下:
2.3 ComboBox¶
下拉框控件算是选项按钮(OptionButton)的文本可编辑版本,也就是说,它可以通过下拉选项列表来选择一个内容之外,还可以直接编辑里面的内容。
下面是一个简单的示例:
效果如下:
第四章:动画
第四章:动画¶
字数 66 个 图片 2 张 阅读时间不到 1 分钟 访问量
章节概述
本章会详细说明如何使用 maliang 来做出一些基本的动画。
既然 tkinter 没有动画,就让 maliang 来弥补吧!
本章内容¶
§4.1 基础动画¶
字数 1564 个 代码 121 行 图片 18 张 阅读时间 7 分钟 访问量
一、动画简述¶
1.1 动画的实现方式¶
在 maliang 中,有两种实现动画的方式,一种是使用 maliang 封装好的动画类,另外一种是使用 tkinter 原生的方式。很显然,这里推荐使用 maliang 封装好的动画类。
1.1.1 maliang 方式¶
使用 maliang 封装的好的动画类既可以极大地简化实现动画的操作,还可以获得一个较好的动画效果。首先,maliang 有一个动画基类,这个动画基类的功能比较强大,可以通过继承它来实现各种各样的动画子类。
此外,maliang 还实现了对动画过程的细微控制,而不是一个简单的开始和结束。说简单点,就是可以通过一个控制函数来控制动画运动的过程。比如说,一个小球从左移动到右这一动画,我们可以通过使用控制函数来实现小球平滑移动这一效果,又或者是回弹的效果,而不是简单的平移。
除了上述说的平滑移动,还有其它很多的方式,只要你设置了合适的控制函数,动画就能按照控制函数那样去运动!
1.1.2 tkinter 原生方式¶
当然,说到底 maliang 封装的动画类也是基于 tkinter 原生动画方式实现的,但要直接使用 tkinter 原生的方式来做出一些动画有一定难度,且不好操控。
下面是一个简单的示例,该示例可以将画布上的一个小球向右平移:
效果如下:(1)
- 注:gif 图限制了帧率为 30 ,实际效果会更流畅一些,后面的同理。
图 1 tkinter 原生动画
虽然使用 tkinter 原生的方式能实现一定的动画效果,但要再想深入实现某些功能就比较复杂了。由于 tkinter 实现动画的方式并不属于本教程的范畴,这里就不深入讲解了。
1.2 控制函数¶
从前面讲述的内容来看,想必你已经大致了解什么是控制函数了。本小节并不会对控制函数做一个详细的说明,这部分会出现在后续章节中。但此处仍指出 maliang 内置的 5 个控制函数:
下面是它们的效果,红绿蓝分别对应上述的前三种控制函数:
图 2 maliang 动画
下面是上述效果的实现代码:
此外,还可以自定义控制函数,这部分会在后续内容中详细讲解。
二、动画类¶
这里说的动画类是动画基类的各个子类,关于动画基类的讲解在后续章节中。
每个动画子类都是对于某一特定动画的具体实现,使用时应该根据需求选取,若没有满足需要的动画子类,也可以基于动画基类继承后实现属于自己的动画子类,即自定义动画类。关于自定义动画类的内容将在后续章节中详述。
2.1 MoveTkWidget¶
MoveTkWidget 用来移动 tkinter 中的原生控件(如 tkinter 的 Label)及其继承的子类(如 maliang 的 Canvas)。
下面是一个简单的示例,利用该类移动 tkinter 的 Label 控件:
效果如下:
图 3 移动 tkinter 原生控件
2.2 MoveWidget¶
MoveWidget 用来移动 maliang 中的控件。
使用方式和上面的类似,下面是一个简单的示例:
效果如下:
图 4 移动控件
2.3 MoveElement¶
MoveElement 用来移动 maliang 中的元素。这里说的元素与上面说的控件有很大的区别,前面章节并没有详细地指出这个问题,这个问题将在后续关于自定义控件和元素的部分详细说明。
下面是一个简单示例:
效果如下:
图 5 移动元素
可以看见,控件的形状和其它部分离了,但这里只是为了演示这个作用和效果,实际中一般并不会这样做。(没事干嘛把形状分离??)
2.4 MoveItem¶
MoveItem 用来移动画布中的基本项。
与其它不同的是,操作 item 必须指明其所属的画布,不然无法对 item 进行操作(1)。下面是一个简单的示例:
- 因为 item 实际只是一个
int类型的对象,自身无法存储其所属画布的相关信息
效果如下:
图 6 移动画布基本项
2.5 GradientTkWidget¶
GradientTkWidget 用来使 tkinter 中的原生控件的相关颜色渐变。
下面是一个简单的示例:
效果如下:
图 7 tkinter 控件的渐变颜色
这个示例使用了 repeat 参数来让这个动画循环进行,repeat 是循环的次数,当次数小于 0 时会无限循环,直到动画类或者程序被终止。
2.6 GradientItem¶
GradientItem 用来使画布中元素的相关颜色渐变。
前面的渐变动画使用了循环,但每次循环之间没有过渡,看起来十分不自然。我们可以给动画类设定一个控制函数来让渐变颜色的起始值和终止值相同,以保证过渡自然。下面是一个简单的示例:
效果与呼吸灯类似:
图 8 画布元素的渐变颜色
2.7 ScaleFontSize¶
ScaleFontSize 用来缩放组件 Text 的字体大小,注意不是控件 Text 的字体大小。
为了让字体的缩放看着更有张力,我们可以试着使用前面提到的 rebound 控制函数,下面是一个简单的示例:
运行上述代码后,字体放大后会再回弹缩小,效果如下:
图 9 tkinter 控件的渐变颜色
特别注意:慎用 ScaleFontSize 类
该类没有对窗口和画布的缩放做适配,在窗口或者画布缩放之后,该类可能会产生意想不到的效果,该效果一般不符合预期要求。
§4.2 控制函数¶
字数 1664 个 代码 32 行 图片 8 张 阅读时间 6 分钟 访问量
一、控制函数¶
1.1 什么是控制函数¶
控制函数可以理解为一个普通的数学函数,一个 float 类型的输入,一个 float 类型的输出,输入代表的是当前动画在时间层面上的进度,范围是 0 到 1,输出代表的是当前动画在图像层面上的进度,范围不限,依据动画情况而定。
表示成数学函数为如下:
当动画是对象在画布上的移动时,输出值的范围一般没有限定,可以负数,表示反向移动,也可以大于 1,表示超出预定的移动距离。但对于颜色渐变这种类型的动画,输出值就有限定了。如果输出值为负数可能会得到意想不到的结果(大概率报错),如果输出值大于 1,则也极有可能得到错误的结果(错误的 RGB 码)。
因此,一般情况下约定输出值的范围在 0 到 1 之间,如果确需超出此范围,应考虑是否修改动画的参数。
1.2 控制函数对动画类的作用¶
动画类实际就是按照给出的帧率以及动画时间来调用关联函数的,而每次调用传给关联函数的值又是经过控制函数计算得出的,而控制函数的结果又是通过传入当前动画时间占比得到的,这个流程图画出来大致如下:
flowchart LR
1(总动画量)
2(关联函数)
3(帧率)
4(动画时间)
5(动画)
6(每帧时间占比 x)
7(每帧动画占比 y)
subgraph 动画类单帧运算过程
6 --控制函数--> 7
end
3 --> 6
4 --> 6
1 --> 2
2 --> 5
7 --> 2
当然,上述只是简化的流程,实际参数和处理过程比上面的流程图要更复杂。
1.3 内置的控制函数¶
前面的 §4.1 基础动画 已经提过内置的 3 个控制函数了,这里将对它们做详细的讲解,并给出函数图像。
从之前的内容来看,不难知道回弹函数在某些情况下是会触发报错的,因为其后半部分图像超出了 1,这就导致类似于颜色渐变这种动画可能报错。
快速理解:看函数的斜率
从控制函数图像其实可以发现,控制函数的斜率就是动画的速度,这一点非常关键。x 值就是实际的时间占比,y 值就是实际的运动占比,时间只可能在 0 ~ 1 之间,而动画可以超出限定的范围(尽管不推荐这样做)。
综上,控制函数是通过控制运动轨迹来控制整个运动的。
上述控制函数是通过控制运动轨迹来控制运动的,那如果我想要的运动轨迹比较复杂,不好写出这个控制函数,但其速度变化曲线,也就是控制函数的导数很容易写出来时,该怎么办呢?关于这一问题将在下一章节进行说明。
二、自定义控制函数¶
2.1 控制函数生成器¶
实际上,maliang 的动画子包还带有一个控制函数生成器(generate),它是一个便捷函数,我们可以通过它来快速得到我们需要的控制函数。控制函数生成器本质上也是一个函数,根据给定的参数来返回新的函数。
每个控制函数都需要明确几个数据:
base: 基本函数,满足输入值为一个浮点数,返回值也是一个浮点数即可;start: 上述基本函数截取区间的起始值;end: 上述基本函数截取区间的终止值;
同时,对于控制函数生成器,还有一点要明确,即参数 map_y 的值,其默认为 True。当 map_y 为 True 时会自动将整个控制函数的值域映射到 [起始值, 1] 上,以保证运动的最终结果和设定的选项一致。此处的起始值表示 \(f(start)\)。
温馨提示:有时候不需要 map_y 为 True
如果你需要往返运动效果的控制函数,那么请将参数 map_y 设为 False。一旦你没有这样做,假设你的最终值为 0,那么将导致映射时其它值被映射到 \(+\infty\),使得动画不可见了。
这里将内置控制函数 rebound 作为示例,讲讲它是怎么生成的。首先,下面是它的函数实现:
可以看见,它实际上就是取正弦函数 0 到 \(\frac{\pi+1}{2}\) 范围内,并约束最终值为 1 的函数。它听起来有点复杂,实际数学表达式如下:
确实比较复杂,但用控制函数生成器写出来却十分简洁。
2.2 完全自定义¶
所谓完全自定义,实际就是不借助控制函数生成器,直接定义的控制函数,一般是控制函数足够简单,或者是有特殊需求的情况下才会使用。典型的如内置控制函数 linear,下面是它的函数实现:
由于它非常简单,所以没必要使用控制函数生成器。
又比如内置控制函数 smooth,下面是它的函数实现:
它看起来并不是那么简单,但把它转化成控制函数生成器的写法是这样的:
这个用控制函数生成器反而又显得复杂了,所以也是直接采用完全自定义的。完全自定义还有助于实现分段函数这样的控制函数。总之,借助控制函数,我们可以实现许多有趣的动画。
三、使用多个控制函数¶
或许你会有同时控制一个对象在水平方向和竖直方向运动的需求,但很遗憾,maliang 的动画类并不支持使用多个控制函数。但是呢,这并不限制我们使用多个动画类来实现类似的需求呀!
下面是一个简单的示例,演示了如何让一个小球同时在水平和竖直方向上运动:
这是它的效果:
图 4 多个动画
是不是非常有趣?当然,这只是使用了两个控制函数,当你学习了 maliang 的 3D 扩展包,使用三个控制函数来控制 3D 对象的运动时,将显得更加有趣了!
§4.3 自定义动画¶
字数 761 个 代码 72 行 阅读时间 3 分钟 访问量
一、动画基类¶
1.1 参数及方法¶
关于动画基类 Animation,在 §4.1 基础动画 中提过一嘴,实现动画的核心就在于这个类。这里说明一下它的相关参数。
ms: 动画时长,单位是毫秒callback: 回调函数,每帧都将调用这个函数,传入当前时间占比controller: 控制函数end: 终止函数,动画一轮结束时会调用这个函数repeat: 重复次数,小于零表示无限次,默认为0fps: 动画帧率,默认为30derivation: 表示是否对控制函数求导,默认为False
此外,动画基类还有两个方法,即 start 和 stop。但是注意,调用 stop 之后这个动画就被彻底终止了,并不是暂停,如果重新调用 start 也只是从头开始运行动画。
下面有一个简单的示例,展示了相关参数的用法:
运行上述示例,可以看见每帧都输出了当前时间占比和实际时长,结束时调用 end 函数。
关于最后一个参数,稍微有些复杂,将在下一部分进行说明。
1.2 控制动画的速度¶
众所周知,位移函数求导之后就是速度函数,正如前面章节 §4.2 控制函数,有时候位置并不好直接修改,但速度比较好控制,这个时候就需要将 derivation 设为 True 了。此时每帧传给回调函数的参数将不在每帧的时间占比了,而是这一帧的时间占比,所有帧的总和为 1(1),也就是函数图像与横纵轴截出来的面积为 1。
- 所以并不是直接的求导,而是求导之后再除以总帧数
那这有什么用呢?当你的回调函数并非直接操控位置时可以尝试使用这个,典型的就是 Canvas 的 move 方法和 moveto 方法。move 使用的是相对坐标,对于单帧而言相当于速度,moveto 使用的是绝对坐标,对于单帧而言就是位置。当我们无法使用 moveto 方法的时候,move 方法配合 derivation 参数就起作用了(如 MoveWidget)。
二、自定义动画类¶
所谓自定义动画类,实际上就是通过继承动画基类并具化为自己需要的类。可以把内置的那些基础动画类作为参考,实现属于自己需要的动画类。当然,若是需求比较简单,那还是直接调用动画基类就好。
下面看一下内置基础动画类 MoveWidget 的源代码:
看起来很多,实际核心内容就一点点。当然,我们自己定义属于自己的动画类时并不需要像上面这样写得如此繁琐。
比如,我们写一个这样的动画类:
运行上述代码,你窗口不停的从透明到清晰,再清晰到透明地变化。
第五章:颜色
第五章:颜色¶
字数 84 个 图片 2 张 阅读时间不到 1 分钟 访问量
章节概述
这一章会讲解如何用 maliang 构建出绚丽的颜色效果。
只会使用默认配色可不是一个好习惯,学会使用各种处理颜色的工具才能写好 GUI 程序。
本章内容¶
§5.1 颜色格式及其转换¶
字数 1592 个 代码 21 行 图片 2 张 阅读时间 6 分钟 访问量
一、颜色格式¶
1.1 tkinter 的颜色¶
tkinter 仅支持颜色名称字符串和像 #RGB 格式的十六进制颜色字符串(如 #RGB 和 #RRGGBB),此处的 R 表示红色的比例(Red),G 表示绿色的比例(Green),B 表示蓝色的比例(Blue)。
下面举例一些 tkinter 能够识别的颜色字符串:
"royalblue""pink""#123""#FF6600"
关于 RGB 颜色格式的其它详细信息,这里不想再额外说明,如果想知道,请自行在别处搜索。
温馨提示:空字符串在 tkinter 中表示没有颜色
空字符串 "" 在 tkinter 中也是可以解析的,表示没有颜色,你也可以将其视为完全透明。在某些情况下这会很有用,比如在 Canvas 中,有些 Item 的边框是有默认颜色的(一般是黑色),如果不想让它们显示出来,就将对应的参数设置为空字符串,这样就变成“透明”了。
1.2 maliang 的颜色¶
maliang 并没有在接口上对 tkinter 做什么修改,只是增加了一些用于颜色的函数方便开发而已。也就是说,maliang 所有涉及到颜色的地方也是用和 tkinter 一样的颜色字符串的方式来传入颜色的。
猜你想问:Python 已内置了模块 colorsys 来提供颜色相关的函数,为什么 maliang 还专门对此有新的内容?
很简单,colorsys 提供的功能很有限,很多轮子都没有,需要自己造。而 maliang 的子包 maliang.color 提供了更多处理颜色的功能。不过要注意的是,colorsys 提供的接口与 maliang 的不一样,不能混用!
虽然在格式上来说,都是颜色字符串,但实际上 maliang 还实验性地支持 #RRGGBBAA 格式的颜色字符串,但这个功能实现的是“伪 RGBA”,只能完成非常有限的功能。
首先,RGBA 中的 A 表示的是透明度(Alpha),与 R、G 和 B 一样,范围是 0~F,F 表示不透明,0 表示完全透明。但是 maliang 提供的 RGBA 并没有真正意义上实现透明度功能,它只是相对于 Canvas 的背景色做了一定处理的颜色而已。限于技术原因,没办法以低性能开销地方式实现真正的透明度功能。下文会对此作详细的介绍。
二、颜色间转换¶
2.1 颜色“标识符”¶
这里所说的“标识符”是 maliang 对一种涉及到的颜色格式的称呼,并非一个类或者常量。maliang 支持处理的颜色“标识符”有下面六种:
rgb: RGB 三元组,例如(12, 34, 56)hsl: HSL 三元组,例如(math.pi, 0.5, 0.5)hex: 十六进制颜色字符串,例如"#ABCDEF"或者"#12345678"name: 颜色名称字符串,例如"royalblue"rgba: RGBA 四元组,例如(12, 34, 56, 78)str: hex(不含八位长度 RGBA 格式的 hex)或 name
其中三位长度与六位长度的 hex 格式和 name 格式可以直接被 tkinter 识别。因此一般情况下,转换后的最终的结果都是这两种格式。虽然这两种可以被直接识别,但并不利于处理,常用的实际上是 rgb 或者其它的格式。这里注意一下,八位长度的 hex 格式的颜色字符串(如 "#12345678")是 maliang 中的“伪 RGBA” 格式,这种是不能被 tkinter 直接识别的,但可以被 maliang 所识别。
关于“伪 RGBA”,假设 Canvas 的背景色是白色,设置的“伪 RGBA”值为 "#FF000078",那么实际呈现的颜色为 "#780000",读者见下面的示例:
其效果如下:
图 1 “伪 RGBA”
很明显,Alpha 设置的值越小,就越透明(和 Tk.alpha 类似)。但多个控件叠加的时候效果并不会像预期的那样,这也是这项功能被称为“伪 RGBA” 的原因。
猜你想问:既然是“伪 RGBA”,那我提前计算出这个 RGBA 的值再设置到控件的样式上不是一样的效果吗?
其实不一样的,写成 RGBA 的格式会好一些。虽然这是“伪 RGBA”,但首先它不需要我们手动去计算,可以减少开发时间;此外,也是最重要的一点,它是动态响应系统主题的!你可以尝试运行上面的代码,然后切换系统的主题,看看这个假的是半透明会不会跟着变化。
当然,能看到变化的前提是,你当前的环境支持跟随系统主题切换程序主题。
2.2 格式间转换¶
虽然上面涉及到的颜色格式很多,但记住它们在 maliang 的“标识符”就能很容易使用这些转换函数了,下面是它们之间的转换函数:
| rgb | hsl | hex | name | rgba | |
|---|---|---|---|---|---|
| rgb | \ | rgb_to_hsl |
rgb_to_hex |
rgb_to_name |
|
| hsl | hsl_to_rgb |
\ | hsl_to_hex |
||
| hex | hex_to_rgb |
hex_to_hsl |
\ | hex_to_name |
hex_to_rgba |
| name | name_to_rgb |
name_to_hex |
\ | ||
| rgba | rgba_to_hex |
\ | |||
| str | str_to_rgb |
具体转换函数的使用方式,可以点击上表中对应函数的文档链接来查看。
温馨提示:颜色转换函数可以使用简化名称来调用
尽管各种颜色格式已经使用“标识符”来简化了,但转换函数的名称仍然比较长,所以 maliang 还为每个转换函数提供了简化的别名,具体来说就是将转换函数中的 “_to_” 给简化为 “2”。举个例子,str_to_rgb 等价于 str2rgb。
下面是一个简单使用颜色转换函数的例子(运行结果为文档构建时计算得到):
很显然,上面四个的结果是一致的。这里需要注意的一点就是,颜色名称字符串是不区分大小写的。
如果想知道有哪些颜色名称字符串可以被 tkinter 直接识别,可以在 colortable.MAPPING_TABLE 中找到。它是一个常量字典,记录了所有 tkinter 可以识别的颜色名称字符串及其对应的 RGB 三元组的值。
§5.2 颜色处理¶
字数 1078 个 代码 47 行 图片 2 张 阅读时间 4 分钟 访问量
一、处理函数¶
maliang 只支持两种颜色空间的处理,分别是 RGB 和 HSL,且对这两种颜色空间支持的相关处理函数都差不多。处理 RGB 的函数位于子包 color.rgb 中,处理 HSL 的函数为位于子包 color.hsl。
1.1 获取相反色¶
以 RGB 颜色为例,这里说的相反色是指颜色某个指标的最大值减去当前值所得的结果,比如 (50, 100, 150) 的相反色就是 (255-50, 255-100, 255-150),即 (205, 155, 105),HSL 颜色同理。
要获取一个颜色的相反色,对于 RGB 颜色,可以使用函数 rgb.contrast,对于 HSL 颜色,可以使用函数 hsl.contrast。两者参数类似。
下面是一个简单的示例(运行结果为文档构建时计算得到):
1.2 过渡一个颜色¶
这里说的过渡一个颜色是指,将一个颜色以另外一个颜色为目标,以一定的比例向其靠拢得到的颜色。显然,当过渡比例为 100% 时,得到的返回值就是目标颜色,0% 时为原来的颜色。对于 RGB,过渡一个颜色要调用的函数为 rgb.transition,对于 HSL 是 hsl.transition。
下面是一个简单的示例(运行结果为文档构建时计算得到):
1.3 混合多个颜色¶
混合颜色就是按权重(默认值表示等权重)分配三个颜色通道的值得到新的颜色。对于 RGB,混合颜色的函数为 rgb.blend,而 HSL 则是 hsl.blend。
下面是一个简单的示例(运行结果为文档构建时计算得到):
1.4 获取一组渐变色¶
其实可以通过设置一系列的值多次调用前面提到的函数 transition 就可以得到一组渐变色,但我并不推荐你使用这种方式获取渐变色,因为内部处理时由于循环可能会导致某些步骤被重复执行导致性能相对低下。对于 RGB 应该使用 rgb.gradient 来获取渐变色,而 HSL 则是 hsl.gradient。
与上面的函数 transition 类似,函数 gradient 也有一个控制到目标颜色比例的参数 rate。这个参数的默认值是 1,表示渐变色的终点就是目标颜色,如果不是 1,那么就是以此参数的值用函数 transition 计算出的颜色作为渐变色的终点。不过,有趣的是,函数 gradient 有一个名为 contoller 的参数可以控制渐变色每次渐变的比例。它要传入的对象是前面第四章提到的控制函数,默认值是 controllers.linear,也就是线性的,等差的。但我们可以通过设置其它的控制函数得到其它的渐变效果。
该函数的返回值是一个列表,里面是一组 RGB 颜色或者 HSL 颜色,数量由参数 count 控制。返回的列表中一般不会包括目标颜色,除非目标颜色与初始颜色相近。
下面是一个简单的示例(运行结果为文档构建时计算得到):
特别注意:控制函数选取需谨慎
默认的控制函数用的是线性的,它的曲线最大值都不会超过 1,所以计算得到的颜色字符串永远都是有意义(除非你传入的初始参数就存在问题)。但有些控制函数,或者自定义的控制函数就可能产生一些问题,比如内置的控制函数 controllers.rebound 就可能会造成产生的颜色字符串无意义。因为这个控制函数的图像中有一部分是超出 1 的,见 第四章第二节图三。
二、一些示例¶
下面给出一些示例以供参考。
2.1 渐变圆¶
这个示例简单使用了 RGB 和 HSL 的渐变色函数,代码如下:
效果如下:
图 1 渐变圆
2.2 呼吸灯效果¶
代码和效果就省略了,具体见 第四章第一节 2.6,现在想必你已经知道那个动画类是怎么实现的了吧?
第六章:主题
第六章:主题¶
字数 167 个 阅读时间 1 分钟 访问量
章节概述
这一章会讲解如何用 maliang 自动适配明暗主题以及调用系统相关主题。
或许你在前面的章节就已经发现了,只要点击网页顶栏的图标 就会出现神奇的事情: 不仅网页的颜色主题切换了,连部分展示的图片的颜色主题也切换了!!
是的,本文档针对颜色主题做了特殊适配,如果你想提前查看预制的明暗颜色主题的效果,就可以通过这种方式。
本章内容¶
- 6.1 切换颜色主题
- 6.2 切换样式主题
§6.1 切换颜色主题¶
字数 840 个 代码 37 行 阅读时间 3 分钟 访问量
特别说明
本页教程仍在撰写中!如出现有误的地方属于正常现象,请放心“食用”,最多也就程序中毒暴毙而已……
一、切换颜色主题的方式¶
maliang 支持两种切换颜色主题的方式,手动调用的方式来切换主题和根据系统的主题自动进行适配。
1.1 手动切换颜色主题¶
目前 maliang 内置的主题有两套,一套亮色主题 "light" 和一套暗色主题 "dark",用户可以通过自定义的方式添加更多主题,名称也不一定要按照什么约定,只要不覆盖内置的主题名称即可。除了内置的两套主题外,还有一个特殊的主题名称不可使用,即后文将提到的 "system"。
不推荐自定义主题:不要没苦硬吃
虽然说用户可以通过自定义的方式添加更多主题,但这里我并不推荐这样做。因为这样做的工作量非常大,且难以移植!曾经的 maliang 在某个版本的时候可以通过导入 JSON 格式的主题配置文件来自定义主题,但随着后续主题功能的重构升级,这个功能目前已被移除。目前只能通过编写 Python 文件的“样式”类来实现自定义主题,这样做非常麻烦,而且一旦后续版本升级 API 发生某些变动,将导致主题不可用!
所以,这里不推荐自定义主题。那可以怎么办呢?等!等我后续更新……看看什么时候有空把 JSON 格式的主题配置文件加回来。
下面是一个简单的示例,它可以强制指定窗口的主题:
同理,你也可以将 "light" 更改为 "dark" 来强制指定颜色主题为暗色。
设置颜色主题的代码并不一定要放在最前面,你也可以将其放到中间。
1.2 自动适配颜色主题¶
自动适配颜色主题的功能默认是开启的,如果你安装了所需要的可选包。maliang 通过调用第三方包 albertosottile/darkdetect 来检测系统主题并跟随系统主题的切换进行切换。但其本质上和上面手动切换的方式一样,只不过这个切换操作是由 maliang 自动完成的。
但为了防止和手动切换颜色主题的功能产生冲突,当 maliang 的主题名称不是 "system" 时,自动适配颜色主题的功能不会生效,也就是说,如果通过某种方式手动改变了应用程序的主题,那么自动适配的功能会失效,只有重新将主题设为 "system" 才会重新生效。
下面是一个示例程序,运行后出现一个分段按钮,你尝试选择不同的主题后查看窗口的变化,并时不时地修改系统的主题,再看看窗口会发生什么变化:
想必你现在应该已经理解它的逻辑了。
二、为主题切换绑定关联函数¶
maliang 还提供了在主题切换时触发已注册的函数的功能。
未完待续……
参考文档
maliang¶
字数 11 个 阅读时间不到 1 分钟 访问量
A lightweight UI framework based on tkinter with all UI drawn in Canvas.
- Website: xiaokang2022.github.io/maliang/
- GitHub: Xiaokang2022/maliang
- PyPI: pypi.org/project/maliang/
If you ❤️ this package, please leave your ⭐ to us, thank you very much!
| 模块 | 描述 |
|---|---|
animation |
A subpackage of |
color |
A subpackage that provides color-related features. |
core |
The core code, you can see the general framework here. |
media |
Extension package of maliang to play media files |
mpl |
Extension package of maliang for matplotlib |
standard |
All standard things. |
table |
Extension package of |
theme |
A subpackage that provides theme-related features. |
three |
Extension package of |
toolbox |
Some practical tools. |
| CLASS | 描述 |
|---|---|
Env |
Configurations for default environment values. |
Font |
Configurations for default font. |
Constant |
All Constants. |
Tk |
Main window. |
Toplevel |
Toplevel window. |
Canvas |
Main contrainer: Canvas. |
TkMessage |
Message pop-up. |
TkColorChooser |
Color chooser pop-up. |
TkFontChooser |
Font chooser pop-up. |
Text |
Text widget, generally used to display plain text. |
Image |
Image widget, generally used to display normal still image. |
Label |
Label widget, which is generally used to display key information. |
Button |
Button widget, typically used to trigger a function. |
Switch |
Switch widget, typically used to control the turning of a function on |
InputBox |
Input box widget, generally used to enter certain information on a single |
CheckBox |
Checkbox button widget, generally used to check some options. |
ToggleButton |
A button that can display information and switch statuses. |
RadioBox |
Radio button widget, generally used to select one of several options. |
ProgressBar |
Progress bar widget, typically used to show the progress of an event. |
UnderlineButton |
Underline button, generally used to display web links. |
HighlightButton |
Highlight button, no outline, which added a highlight effect. |
IconButton |
A button with an icon on the left side. |
Slider |
A slider for visually resizing values. |
SegmentedButton |
A segmented button that can be used to toggle between multiple states. |
SpinBox |
A widget that makes it easy to enter numeric type data. |
OptionButton |
A button that has many options to choose. |
ComboBox |
An input box that can provide several options. |
Spinner |
Spinners visually communicate that something is processing. |
Tooltip |
A tooltip that can display additional information. |
PhotoImage |
Pillow version of |
| 函数 | 描述 |
|---|---|
reset |
Reset all configuration options. |
Env
¶
Configurations for default environment values.
| 属性 | 描述 |
|---|---|
system |
The system of environment, such as
TYPE:
|
theme |
The theme of the application.
TYPE:
|
gradient_animation |
Whether to enable gradient animation for widgets that support it by default.
TYPE:
|
auto_update |
Whether to check for updates automatically on startup.
TYPE:
|
root |
The current default root window. It is READ-ONLY. |
| 方法 | 描述 |
|---|---|
reset |
Reset all configuration options. |
get_default_system |
Get the system of environment. |
Font
¶
Constant
¶
All Constants.
| 属性 | 描述 |
|---|---|
GOLDEN_RATIO |
The golden ratio, which is needed to automatically calculate the color |
PREDEFINED_EVENTS |
Predefined events that can be used directly without registration. It is |
PREDEFINED_VIRTUAL_EVENTS |
Predefined virtual events that can be used directly without |
GOLDEN_RATIO
class-attribute
instance-attribute
¶
The golden ratio, which is needed to automatically calculate the color
of widget on "disabled" state. It is READ-ONLY.
PREDEFINED_EVENTS
class-attribute
instance-attribute
¶
PREDEFINED_EVENTS: Final[tuple[str, ...]] = (
"<KeyPress>",
"<KeyRelease>",
"<Button-1>",
"<Button-2>",
"<Button-3>",
"<Button-4>",
"<Button-5>",
"<ButtonRelease-1>",
"<ButtonRelease-2>",
"<ButtonRelease-3>",
"<MouseWheel>",
"<Motion>",
"<B1-Motion>",
"<B2-Motion>",
"<B3-Motion>",
"<Configure>",
)
Predefined events that can be used directly without registration. It is READ-ONLY.
Tk
¶
Tk(
size: tuple[int, int] = (1280, 720),
position: tuple[int, int] | None = None,
*,
title: str | None = None,
icon: str | enhanced.PhotoImage | None = None,
**kwargs: Any,
)
Main window.
In general, there is only one main window. But after destroying it, another one can be created.
| 属性 | 描述 |
|---|---|
light |
the color theme of light mode. |
dark |
the color theme of dark mode. |
| 参数 | 描述 |
|---|---|
|
size of the window. |
|
position of the window, based on the upper left corner. And negative numbers are based on the bottom right corner. |
|
title of the window, default value is
类型:
|
|
icon of the window, default value is the icon of tk.
类型:
|
|
additional keyword arguments for
类型:
|
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the window. |
geometry |
Change the size and position of the window and return the current |
center |
Center the container. |
icon |
Set the icon of the window. |
alpha |
Set or get the transparency of the window. |
topmost |
Set or get whether the window is pinned or not. |
fullscreen |
Set or get whether the window is full-screen. |
toolwindow |
Set or get whether the window is tool-window. |
transparentcolor |
Set or get the penetration color of the window. |
modified |
Set or get whether the window is modified. |
transparent |
Set or get whether the window is transparent. |
destroy |
Destroy the object. |
at_exit |
Set a function that will be called when the window is closed. |
theme
¶
theme(
value: Literal["light", "dark"], *, include_children: bool = True, include_canvases: bool = True
) -> None
geometry
¶
geometry(
*, size: tuple[int, int] | None = None, position: tuple[int, int] | None = None
) -> tuple[int, int, int, int] | None
Change the size and position of the window and return the current size and position of the window.
| 参数 | 描述 |
|---|---|
|
the size of the window, if it is |
|
the position of the window, if it is |
| 返回 | 描述 |
|---|---|
tuple[int, int, int, int] | None
|
The current size and position of the window if |
Note
If you want to use tkinter.Tk.geometry, please use
tkinter.Tk.wm_geometry instead.
center
¶
icon
¶
icon(value: str | enhanced.PhotoImage) -> None
Set the icon of the window.
| 参数 | 描述 |
|---|---|
|
the icon.
类型:
|
alpha
¶
topmost
¶
fullscreen
¶
Set or get whether the window is full-screen.
| 参数 | 描述 |
|---|---|
|
indicate whether the window is full-screen.
类型:
|
| 返回 | 描述 |
|---|---|
bool | None
|
The current full-screen state of the window if |
Note
The method should be called at the end of the code, or after some time after the program has started.
toolwindow
¶
transparentcolor
¶
modified
¶
transparent
¶
Toplevel
¶
Toplevel(
master: Tk | Toplevel | None = None,
size: tuple[int, int] = (960, 540),
position: tuple[int, int] | None = None,
*,
title: str | None = None,
icon: str | enhanced.PhotoImage | None = None,
grab: bool = False,
focus: bool = True,
**kwargs: Any,
)
Bases: tkinter.Toplevel, Tk, Misc
Toplevel window.
It can be used as a pop-up window, or it can be customized to put anything you want to show.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
size of the window, default value is 960x540(px). |
|
position of the window, default value indicates random. |
|
title of window, default is the same as title of master.
类型:
|
|
icon of the window, default is the same as title of master.
类型:
|
|
whether to grab the window.
类型:
|
|
whether direct input focus to this window.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
destroy |
Destroy the object. |
Canvas
¶
Canvas(
master: Tk | Toplevel | Canvas | None = None,
*,
expand: Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: Literal["min", "max"] | None = None,
free_anchor: bool = False,
auto_update: bool | None = None,
zoom_all_items: bool = False,
**kwargs: Any,
)
Main contrainer: Canvas.
The parent widget of all virtual widgets is Canvas.
| 属性 | 描述 |
|---|---|
light |
light theme colors. |
dark |
dark theme colors. |
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Canvas and its items. |
zoom |
Resize and position the |
destroy |
Destroy the object. |
clear |
Clear all things in the Canvas. |
on_motion |
Events to move the mouse. |
on_click |
Events to active the mouse. |
on_release |
Events to release the mouse. |
on_wheel |
Events to scroll the mouse wheel. |
on_key_press |
Events for typing. |
on_key_release |
Events for typing. |
register_event |
Register a event to process. |
hide_focus |
Hide the focus rectangle. |
theme
¶
zoom
¶
Resize and position the Canvas based on the relevant parameters.
This method only works for Canvas with Place layout.
on_wheel
¶
Events to scroll the mouse wheel.
TkMessage
¶
TkMessage(
message: str | None = None,
detail: str | None = None,
*,
title: str | None = None,
icon: Literal["error", "info", "question", "warning"] = "info",
option: Literal[
"abortretryignore", "ok", "okcancel", "retrycancel", "yesno", "yesnocancel"
] = "ok",
default: Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"] | None = None,
master: tkinter.Tk | None = None,
command: Callable[[Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"]], Any]
| None = None,
)
Message pop-up.
| 参数 | 描述 |
|---|---|
|
message.
类型:
|
|
detail message.
类型:
|
|
title of the window.
类型:
|
|
icon.
类型:
|
|
type of the message pop-up.
类型:
|
|
button where the focus is, default is the leftmost one.
类型:
|
|
parent widget. |
|
callback function.
类型:
|
TkColorChooser
¶
TkFontChooser
¶
Text
¶
Text(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
wrap_length: int | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Text widget, generally used to display plain text.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
limit the length of text, beyond which it will automatically wrap.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Image
¶
Image(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Image widget, generally used to display normal still image.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the image of the widget. |
set |
Set the image of the widget. |
Label
¶
Label(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Label widget, which is generally used to display key information.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Button
¶
Button(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Button widget, typically used to trigger a function.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Switch
¶
Switch(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 60,
*,
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Switch widget, typically used to control the turning of a function on and off.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the switch is changed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the switch. |
set |
Set the state of the switch. |
InputBox
¶
InputBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
align: Literal["left", "right", "center"] = "left",
placeholder: str = "",
show: str | None = None,
ignore: tuple[str, ...] = ("\n", "\r"),
limit: int = -1,
limit_width: int = 0,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Input box widget, generally used to enter certain information on a single line.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
ignore the input of some characters. |
|
a placeholder for the prompt.
类型:
|
|
limit on the number of characters.
类型:
|
|
limit on the width of characters.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the value of the Entry. |
set |
Set the text value of the Entry. |
insert |
Insert. |
append |
Append text to Entry. |
remove |
Remove. |
pop |
Delete a specified amount of text. |
clear |
Clear the text value of the Entry. |
update |
Update the widget. |
CheckBox
¶
CheckBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 30,
*,
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Checkbox button widget, generally used to check some options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of check button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the check button. |
set |
Set the state of the check button. |
ToggleButton
¶
ToggleButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button that can display information and switch statuses.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of check button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the check button. |
set |
Set the state of the switch. |
RadioBox
¶
RadioBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 30,
*,
default: bool | None = None,
command: Callable[[int], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Radio button widget, generally used to select one of several options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of radio button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the radio button. |
set |
Set the state of the radio button. |
group |
Combine other radio boxes. |
ProgressBar
¶
ProgressBar(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (400, 20),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Progress bar widget, typically used to show the progress of an event.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget
类型:
|
|
a function that is triggered when the progress of progress bar is 100%. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the progress of the progress bar. |
set |
Set the progress of the progress bar. |
UnderlineButton
¶
UnderlineButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool = False,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Underline button, generally used to display web links.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the underline button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
HighlightButton
¶
HighlightButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Highlight button, no outline, which added a highlight effect.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the hightlight button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
IconButton
¶
IconButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button with an icon on the left side.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Slider
¶
Slider(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (400, 30),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A slider for visually resizing values.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the value of the slider. |
set |
Set the value of the slider. |
SegmentedButton
¶
SegmentedButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
sizes: tuple[tuple[int, int], ...] = (),
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
layout: Literal["horizontal", "vertical"] = "horizontal",
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A segmented button that can be used to toggle between multiple states.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
layout mode of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
SpinBox
¶
SpinBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
format_spec: str = "d",
step: float = 1,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
align: Literal["left", "right", "center"] = "left",
placeholder: str = "",
show: str | None = None,
limit: int = math.inf,
default: str | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A widget that makes it easy to enter numeric type data.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
format of value.
类型:
|
|
value of each change.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
a placeholder for the prompt.
类型:
|
|
limit on the number of characters. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
change |
Try change the current value. |
get |
Get the value of the Entry. |
set |
Set the text value of the Entry. |
append |
Append text to Entry. |
delete |
Delete a specified amount of text. |
clear |
Clear the text value of the Entry. |
OptionButton
¶
OptionButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
align: Literal["up", "center", "down"] = "center",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button that has many options to choose.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
align of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
ComboBox
¶
ComboBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
align: Literal["up", "down"] = "down",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
An input box that can provide several options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
align of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
Spinner
¶
Spinner(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (30, 30),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
widths: tuple[int, int] | None = None,
mode: Literal["determinate", "indeterminate"] = "determinate",
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Spinners visually communicate that something is processing.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the progress of progress bar is 100%. |
|
width of the outside ring and inside ring. |
|
mode of the Spinner.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the progress of the Spinner. |
set |
Set the progress of the Spinner. |
destroy |
Destroy the widget. |
Tooltip
¶
Tooltip(
widget: virtual.Widget,
size: tuple[int, int] | None = None,
*,
text: str = "",
align: Literal["up", "down", "right", "left", "center"] = "down",
padding: int = 3,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A tooltip that can display additional information.
| 参数 | 描述 |
|---|---|
|
the associated widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
align mode of the tooltip.
类型:
|
|
extra padding between tooltip and the associated widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
PhotoImage
¶
Bases: ImageTk.PhotoImage, tkinter.PhotoImage
Pillow version of tkinter.PhotoImage.
| 方法 | 描述 |
|---|---|
scale |
Scale the PhotoImage. |
resize |
Resize the PhotoImage. |
animation
maliang.animation¶
字数 11 个 阅读时间不到 1 分钟 访问量
源代码:maliang/animation/__init__.py
A subpackage of maliang that provides animation-related features.
A highly customizable animation base class and related subclasses are provided,
as well as highly customizable control functions. In addition, control
functions also applies to the related functions of the color subpackage.
| 模块 | 描述 |
|---|---|
animations |
Base and standard animation classes. |
controllers |
Controller generator and standard control functions. |
| CLASS | 描述 |
|---|---|
Animation |
Base animation class. |
MoveWindow |
Animation of moving the window. |
MoveTkWidget |
Animation of moving |
MoveWidget |
Animation of moving |
MoveElement |
Animation of moving |
MoveItem |
Animation of moving a item of |
GradientTkWidget |
Animation of making the color of |
GradientItem |
Animation of making the color of canvas item to be gradient. |
ScaleFontSize |
Animation of scaling the font size of |
| 函数 | 描述 |
|---|---|
generate |
Generate a control function from an ordinary mathematical function. |
linear |
Speed remains the same. |
smooth |
Speed is slow first, then fast and then slow. (slow -> fast -> slow) |
rebound |
Before the end, displacement will bounce off a bit. |
ease_in |
Gradually accelerate. (slow -> fast) |
ease_out |
Gradually decelerate. (fast -> slow) |
Animation
¶
Animation(
duration: int,
command: Callable[[float], Any],
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
derivation: bool = False,
)
Base animation class.
| 属性 | 描述 |
|---|---|
command |
callback function, which will be called once per frame.
|
controller |
a function that controls the animation process.
|
end |
end function, which is called once at the end of the animation.
|
repeat |
number of repetitions of the animation.
|
repeat_delay |
length of the delay before the animation repeats.
|
derivation |
whether the callback function is derivative.
|
| 参数 | 描述 |
|---|---|
|
duration of the animation, in milliseconds.
类型:
|
|
callback function, which will be called once per frame. |
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
| 方法 | 描述 |
|---|---|
start |
Start the animation. |
stop |
Stop the animation. |
skip |
Skip some loops. |
MoveWindow
¶
MoveWindow(
window: tkinter.Tk | tkinter.Toplevel | containers.Tk | containers.Toplevel,
offset: tuple[float, float],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
)
Bases: Animation
Animation of moving the window.
| 参数 | 描述 |
|---|---|
|
the window to be moved.
类型:
|
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
MoveTkWidget
¶
MoveTkWidget(
widget: tkinter.Widget,
offset: tuple[float, float],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
)
Bases: Animation
Animation of moving tkinter.Widget.
| 参数 | 描述 |
|---|---|
|
the |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
| 引发 | 描述 |
|---|---|
RuntimeError
|
if the widget is not laid out by Place. |
MoveWidget
¶
Bases: Animation
Animation of moving virtual.Widget.
| 参数 | 描述 |
|---|---|
|
the |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
MoveElement
¶
Bases: Animation
Animation of moving virtual.Element.
| 参数 | 描述 |
|---|---|
|
the |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
MoveItem
¶
Bases: Animation
Animation of moving a item of tkinter.Canvas.
| 参数 | 描述 |
|---|---|
|
an instance of
类型:
|
|
the item to be moved. |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
GradientTkWidget
¶
Bases: Animation
Animation of making the color of tkinter.Widget to be gradient.
| 参数 | 描述 |
|---|---|
|
the |
|
parameter name of widget that is to be modified in color.
类型:
|
|
a tuple of the initial and ending colors. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
| 引发 | 描述 |
|---|---|
ValueError
|
if any color in |
GradientItem
¶
GradientItem(
canvas: tkinter.Canvas | containers.Canvas,
item: int,
parameter: str,
colors: tuple[str, str],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
derivation: bool = False,
)
GradientItem(
canvas: tkinter.Canvas | containers.Canvas,
item: Sequence[int],
parameter: str,
colors: tuple[str, str],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
derivation: bool = False,
)
Bases: Animation
Animation of making the color of canvas item to be gradient.
| 参数 | 描述 |
|---|---|
|
an instance of
类型:
|
|
item whose color is to be gradient. |
|
parameter name of item that is to be modified in color.
类型:
|
|
a tuple of the initial and ending colors. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
| 引发 | 描述 |
|---|---|
ValueError
|
if any color in |
ScaleFontSize
¶
Bases: Animation
Animation of scaling the font size of virtual.Text.
| 参数 | 描述 |
|---|---|
|
an instance of |
|
a tuple of the initial and ending sizes or target font size. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
generate
¶
Generate a control function from an ordinary mathematical function.
| 参数 | 描述 |
|---|---|
|
base function, an ordinary mathematical function. |
|
the first value of the parameter of the base function.
类型:
|
|
the last value of the parameter of the base function.
类型:
|
|
whether map the final return value to
类型:
|
| 返回 | 描述 |
|---|---|
Callable[[float], float]
|
A control function. |
smooth
¶
Speed is slow first, then fast and then slow. (slow -> fast -> slow)
maliang.animation.animations¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/animation/animations.py
Base and standard animation classes.
The animation base class can be inherited or called directly. Other standard animation classes are best used by direct calls, rather than inheritance.
| CLASS | 描述 |
|---|---|
Animation |
Base animation class. |
MoveWindow |
Animation of moving the window. |
MoveTkWidget |
Animation of moving |
MoveWidget |
Animation of moving |
MoveElement |
Animation of moving |
MoveItem |
Animation of moving a item of |
GradientTkWidget |
Animation of making the color of |
GradientItem |
Animation of making the color of canvas item to be gradient. |
ScaleFontSize |
Animation of scaling the font size of |
Animation
¶
Animation(
duration: int,
command: Callable[[float], Any],
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
derivation: bool = False,
)
Base animation class.
| 属性 | 描述 |
|---|---|
command |
callback function, which will be called once per frame.
|
controller |
a function that controls the animation process.
|
end |
end function, which is called once at the end of the animation.
|
repeat |
number of repetitions of the animation.
|
repeat_delay |
length of the delay before the animation repeats.
|
derivation |
whether the callback function is derivative.
|
| 参数 | 描述 |
|---|---|
|
duration of the animation, in milliseconds.
类型:
|
|
callback function, which will be called once per frame. |
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
| 方法 | 描述 |
|---|---|
start |
Start the animation. |
stop |
Stop the animation. |
skip |
Skip some loops. |
MoveWindow
¶
MoveWindow(
window: tkinter.Tk | tkinter.Toplevel | containers.Tk | containers.Toplevel,
offset: tuple[float, float],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
)
Bases: Animation
Animation of moving the window.
| 参数 | 描述 |
|---|---|
|
the window to be moved.
类型:
|
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
MoveTkWidget
¶
MoveTkWidget(
widget: tkinter.Widget,
offset: tuple[float, float],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
)
Bases: Animation
Animation of moving tkinter.Widget.
| 参数 | 描述 |
|---|---|
|
the |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
| 引发 | 描述 |
|---|---|
RuntimeError
|
if the widget is not laid out by Place. |
MoveWidget
¶
Bases: Animation
Animation of moving virtual.Widget.
| 参数 | 描述 |
|---|---|
|
the |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
MoveElement
¶
Bases: Animation
Animation of moving virtual.Element.
| 参数 | 描述 |
|---|---|
|
the |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
MoveItem
¶
Bases: Animation
Animation of moving a item of tkinter.Canvas.
| 参数 | 描述 |
|---|---|
|
an instance of
类型:
|
|
the item to be moved. |
|
relative offset of the coordinates. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
GradientTkWidget
¶
Bases: Animation
Animation of making the color of tkinter.Widget to be gradient.
| 参数 | 描述 |
|---|---|
|
the |
|
parameter name of widget that is to be modified in color.
类型:
|
|
a tuple of the initial and ending colors. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
| 引发 | 描述 |
|---|---|
ValueError
|
if any color in |
GradientItem
¶
GradientItem(
canvas: tkinter.Canvas | containers.Canvas,
item: int,
parameter: str,
colors: tuple[str, str],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
derivation: bool = False,
)
GradientItem(
canvas: tkinter.Canvas | containers.Canvas,
item: Sequence[int],
parameter: str,
colors: tuple[str, str],
duration: int,
*,
controller: Callable[[float], float] = controllers.linear,
end: Callable[[], Any] | None = None,
fps: int = 30,
repeat: int = 0,
repeat_delay: int = 0,
derivation: bool = False,
)
Bases: Animation
Animation of making the color of canvas item to be gradient.
| 参数 | 描述 |
|---|---|
|
an instance of
类型:
|
|
item whose color is to be gradient. |
|
parameter name of item that is to be modified in color.
类型:
|
|
a tuple of the initial and ending colors. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
| 引发 | 描述 |
|---|---|
ValueError
|
if any color in |
ScaleFontSize
¶
Bases: Animation
Animation of scaling the font size of virtual.Text.
| 参数 | 描述 |
|---|---|
|
an instance of |
|
a tuple of the initial and ending sizes or target font size. |
|
duration of the animation, in milliseconds.
类型:
|
|
a function that controls the animation process.
类型:
|
|
end function, which is called once at the end of the animation. |
|
frame rate of the animation.
类型:
|
|
number of repetitions of the animation.
类型:
|
|
length of the delay before the animation repeats.
类型:
|
|
whether the callback function is derivative.
类型:
|
maliang.animation.controllers¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/animation/controllers.py
Controller generator and standard control functions.
Definition of control function:
1 2 3 4 5 6 7 8 9 | |
| 函数 | 描述 |
|---|---|
generate |
Generate a control function from an ordinary mathematical function. |
linear |
Speed remains the same. |
smooth |
Speed is slow first, then fast and then slow. (slow -> fast -> slow) |
rebound |
Before the end, displacement will bounce off a bit. |
ease_in |
Gradually accelerate. (slow -> fast) |
ease_out |
Gradually decelerate. (fast -> slow) |
generate
¶
Generate a control function from an ordinary mathematical function.
| 参数 | 描述 |
|---|---|
|
base function, an ordinary mathematical function. |
|
the first value of the parameter of the base function.
类型:
|
|
the last value of the parameter of the base function.
类型:
|
|
whether map the final return value to
类型:
|
| 返回 | 描述 |
|---|---|
Callable[[float], float]
|
A control function. |
smooth
¶
Speed is slow first, then fast and then slow. (slow -> fast -> slow)
color
maliang.color¶
字数 11 个 阅读时间不到 1 分钟 访问量
A subpackage that provides color-related features.
Supports the processing of color strings in RGB and HSL formats, as well as the conversion between color names and color codes.
| 模块 | 描述 |
|---|---|
colortable |
Mapping table between the color names and the RGB codes. |
convert |
Convert a format of color to another format. |
hsl |
Some functions about HSL codes. |
rgb |
Some functions about RGB codes. |
| 函数 | 描述 |
|---|---|
rgb_to_hex |
Convert a RGB code to a hexadecimal code. |
hex_to_rgb |
Convert a hexadecimal code to a RGB code. |
rgba_to_hex |
Convert a RGBA code to a hexadecimal code. |
hex_to_rgba |
Convert a hexadecimal code to a RGBA code. |
hsl_to_rgb |
Convert a HSL code to a RGB code. |
rgb_to_hsl |
Convert a RGB code to a HSL code. |
hsl_to_hex |
Convert a HSL code to a hexadecimal code. |
hex_to_hsl |
Convert a hexadecimal code to a HSL code. |
name_to_rgb |
Convert a color name to a RGB code. |
rgb_to_name |
Convert a RGB code to a color name. |
name_to_hex |
Convert a color name to a hexadecimal code. |
hex_to_name |
Convert a hexadecimal code to a color name. |
fix_hex_length |
Fix the length of a hexadecimal code. |
str_to_rgb |
Convert a color name or a hexadecimal code to a RGB code. |
maliang.color.colortable¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/color/colortable.py
Mapping table between the color names and the RGB codes.
| 属性 | 描述 |
|---|---|
MAPPING_TABLE |
Mapping table for color names to RGB codes. |
MAPPING_TABLE
module-attribute
¶
MAPPING_TABLE: Final[dict[str, tuple[int, int, int]]] = {
"alice blue": (240, 248, 255),
"aliceblue": (240, 248, 255),
"antique white": (250, 235, 215),
"antiquewhite": (250, 235, 215),
"antiquewhite1": (255, 239, 219),
"antiquewhite2": (238, 223, 204),
"antiquewhite3": (205, 192, 176),
"antiquewhite4": (139, 131, 120),
"agua": (0, 255, 255),
"aquamarine": (127, 255, 212),
"aquamarine1": (127, 255, 212),
"aquamarine2": (118, 238, 198),
"aquamarine3": (102, 205, 170),
"aquamarine4": (69, 139, 116),
"azure": (240, 255, 255),
"azure1": (240, 255, 255),
"azure2": (224, 238, 238),
"azure3": (193, 205, 205),
"azure4": (131, 139, 139),
"beige": (245, 245, 220),
"bisque": (255, 228, 196),
"bisque1": (255, 228, 196),
"bisque2": (238, 213, 183),
"bisque3": (205, 183, 158),
"bisque4": (139, 125, 107),
"black": (0, 0, 0),
"blanched almond": (255, 235, 205),
"blanchedalmond": (255, 235, 205),
"blue": (0, 0, 255),
"blue violet": (138, 43, 226),
"blue1": (0, 0, 255),
"blue2": (0, 0, 238),
"blue3": (0, 0, 205),
"blue4": (0, 0, 139),
"blueviolet": (138, 43, 226),
"brown": (165, 42, 42),
"brown1": (255, 64, 64),
"brown2": (238, 59, 59),
"brown3": (205, 51, 51),
"brown4": (139, 35, 35),
"burlywood": (222, 184, 135),
"burlywood1": (255, 211, 155),
"burlywood2": (238, 197, 145),
"burlywood3": (205, 170, 125),
"burlywood4": (139, 115, 85),
"cadet blue": (95, 158, 160),
"cadetblue": (95, 158, 160),
"cadetblue1": (152, 245, 255),
"cadetblue2": (142, 229, 238),
"cadetblue3": (122, 197, 205),
"cadetblue4": (83, 134, 139),
"chartreuse": (127, 255, 0),
"chartreuse1": (127, 255, 0),
"chartreuse2": (118, 238, 0),
"chartreuse3": (102, 205, 0),
"chartreuse4": (69, 139, 0),
"chocolate": (210, 105, 30),
"chocolate1": (255, 127, 36),
"chocolate2": (238, 118, 33),
"chocolate3": (205, 102, 29),
"chocolate4": (139, 69, 19),
"coral": (255, 127, 80),
"coral1": (255, 114, 86),
"coral2": (238, 106, 80),
"coral3": (205, 91, 69),
"coral4": (139, 62, 47),
"cornflower blue": (100, 149, 237),
"cornflowerblue": (100, 149, 237),
"cornsilk": (255, 248, 220),
"cornsilk1": (255, 248, 220),
"cornsilk2": (238, 232, 205),
"cornsilk3": (205, 200, 177),
"cornsilk4": (139, 136, 120),
"crymson": (220, 20, 60),
"cyan": (0, 255, 255),
"cyan1": (0, 255, 255),
"cyan2": (0, 238, 238),
"cyan3": (0, 205, 205),
"cyan4": (0, 139, 139),
"dark blue": (0, 0, 139),
"dark cyan": (0, 139, 139),
"dark goldenrod": (184, 134, 11),
"dark gray": (169, 169, 169),
"dark green": (0, 100, 0),
"dark grey": (169, 169, 169),
"dark khaki": (189, 183, 107),
"dark magenta": (139, 0, 139),
"dark olive green": (85, 107, 47),
"dark orange": (255, 140, 0),
"dark orchid": (153, 50, 204),
"dark red": (139, 0, 0),
"dark salmon": (233, 150, 122),
"dark sea green": (143, 188, 143),
"dark slate blue": (72, 61, 139),
"dark slate gray": (47, 79, 79),
"dark slate grey": (47, 79, 79),
"dark turquoise": (0, 206, 209),
"dark violet": (148, 0, 211),
"darkblue": (0, 0, 139),
"darkcyan": (0, 139, 139),
"darkgoldenrod": (184, 134, 11),
"darkgoldenrod1": (255, 185, 15),
"darkgoldenrod2": (238, 173, 14),
"darkgoldenrod3": (205, 149, 12),
"darkgoldenrod4": (139, 101, 8),
"darkgray": (169, 169, 169),
"darkgreen": (0, 100, 0),
"darkgrey": (169, 169, 169),
"darkkhaki": (189, 183, 107),
"darkmagenta": (139, 0, 139),
"darkolivegreen": (85, 107, 47),
"darkolivegreen1": (202, 255, 112),
"darkolivegreen2": (188, 238, 104),
"darkolivegreen3": (162, 205, 90),
"darkolivegreen4": (110, 139, 61),
"darkorange": (255, 140, 0),
"darkorange1": (255, 127, 0),
"darkorange2": (238, 118, 0),
"darkorange3": (205, 102, 0),
"darkorange4": (139, 69, 0),
"darkorchid": (153, 50, 204),
"darkorchid1": (191, 62, 255),
"darkorchid2": (178, 58, 238),
"darkorchid3": (154, 50, 205),
"darkorchid4": (104, 34, 139),
"darkred": (139, 0, 0),
"darksalmon": (233, 150, 122),
"darkseagreen": (143, 188, 143),
"darkseagreen1": (193, 255, 193),
"darkseagreen2": (180, 238, 180),
"darkseagreen3": (155, 205, 155),
"darkseagreen4": (105, 139, 105),
"darkslateblue": (72, 61, 139),
"darkslategray": (47, 79, 79),
"darkslategray1": (151, 255, 255),
"darkslategray2": (141, 238, 238),
"darkslategray3": (121, 205, 205),
"darkslategray4": (82, 139, 139),
"darkslategrey": (47, 79, 79),
"darkturquoise": (0, 206, 209),
"darkviolet": (148, 0, 211),
"deep pink": (255, 20, 147),
"deep sky blue": (0, 191, 255),
"deeppink": (255, 20, 147),
"deeppink1": (255, 20, 147),
"deeppink2": (238, 18, 137),
"deeppink3": (205, 16, 118),
"deeppink4": (139, 10, 80),
"deepskyblue": (0, 191, 255),
"deepskyblue1": (0, 191, 255),
"deepskyblue2": (0, 178, 238),
"deepskyblue3": (0, 154, 205),
"deepskyblue4": (0, 104, 139),
"dim gray": (105, 105, 105),
"dim grey": (105, 105, 105),
"dimgray": (105, 105, 105),
"dimgrey": (105, 105, 105),
"dodger blue": (30, 144, 255),
"dodgerblue": (30, 144, 255),
"dodgerblue1": (30, 144, 255),
"dodgerblue2": (28, 134, 238),
"dodgerblue3": (24, 116, 205),
"dodgerblue4": (16, 78, 139),
"firebrick": (178, 34, 34),
"firebrick1": (255, 48, 48),
"firebrick2": (238, 44, 44),
"firebrick3": (205, 38, 38),
"firebrick4": (139, 26, 26),
"floral white": (255, 250, 240),
"floralwhite": (255, 250, 240),
"forest green": (34, 139, 34),
"forestgreen": (34, 139, 34),
"fuchsia": (255, 0, 255),
"gainsboro": (220, 220, 220),
"ghost white": (248, 248, 255),
"ghostwhite": (248, 248, 255),
"gold": (255, 215, 0),
"gold1": (255, 215, 0),
"gold2": (238, 201, 0),
"gold3": (205, 173, 0),
"gold4": (139, 117, 0),
"goldenrod": (218, 165, 32),
"goldenrod1": (255, 193, 37),
"goldenrod2": (238, 180, 34),
"goldenrod3": (205, 155, 29),
"goldenrod4": (139, 105, 20),
"gray": (128, 128, 128),
"gray0": (0, 0, 0),
"gray1": (3, 3, 3),
"gray2": (5, 5, 5),
"gray3": (8, 8, 8),
"gray4": (10, 10, 10),
"gray5": (13, 13, 13),
"gray6": (15, 15, 15),
"gray7": (18, 18, 18),
"gray8": (20, 20, 20),
"gray9": (23, 23, 23),
"gray10": (26, 26, 26),
"gray11": (28, 28, 28),
"gray12": (31, 31, 31),
"gray13": (33, 33, 33),
"gray14": (36, 36, 36),
"gray15": (38, 38, 38),
"gray16": (41, 41, 41),
"gray17": (43, 43, 43),
"gray18": (46, 46, 46),
"gray19": (48, 48, 48),
"gray20": (51, 51, 51),
"gray21": (54, 54, 54),
"gray22": (56, 56, 56),
"gray23": (59, 59, 59),
"gray24": (61, 61, 61),
"gray25": (64, 64, 64),
"gray26": (66, 66, 66),
"gray27": (69, 69, 69),
"gray28": (71, 71, 71),
"gray29": (74, 74, 74),
"gray30": (77, 77, 77),
"gray31": (79, 79, 79),
"gray32": (82, 82, 82),
"gray33": (84, 84, 84),
"gray34": (87, 87, 87),
"gray35": (89, 89, 89),
"gray36": (92, 92, 92),
"gray37": (94, 94, 94),
"gray38": (97, 97, 97),
"gray39": (99, 99, 99),
"gray40": (102, 102, 102),
"gray41": (105, 105, 105),
"gray42": (107, 107, 107),
"gray43": (110, 110, 110),
"gray44": (112, 112, 112),
"gray45": (115, 115, 115),
"gray46": (117, 117, 117),
"gray47": (120, 120, 120),
"gray48": (122, 122, 122),
"gray49": (125, 125, 125),
"gray50": (127, 127, 127),
"gray51": (130, 130, 130),
"gray52": (133, 133, 133),
"gray53": (135, 135, 135),
"gray54": (138, 138, 138),
"gray55": (140, 140, 140),
"gray56": (143, 143, 143),
"gray57": (145, 145, 145),
"gray58": (148, 148, 148),
"gray59": (150, 150, 150),
"gray60": (153, 153, 153),
"gray61": (156, 156, 156),
"gray62": (158, 158, 158),
"gray63": (161, 161, 161),
"gray64": (163, 163, 163),
"gray65": (166, 166, 166),
"gray66": (168, 168, 168),
"gray67": (171, 171, 171),
"gray68": (173, 173, 173),
"gray69": (176, 176, 176),
"gray70": (179, 179, 179),
"gray71": (181, 181, 181),
"gray72": (184, 184, 184),
"gray73": (186, 186, 186),
"gray74": (189, 189, 189),
"gray75": (191, 191, 191),
"gray76": (194, 194, 194),
"gray77": (196, 196, 196),
"gray78": (199, 199, 199),
"gray79": (201, 201, 201),
"gray80": (204, 204, 204),
"gray81": (207, 207, 207),
"gray82": (209, 209, 209),
"gray83": (212, 212, 212),
"gray84": (214, 214, 214),
"gray85": (217, 217, 217),
"gray86": (219, 219, 219),
"gray87": (222, 222, 222),
"gray88": (224, 224, 224),
"gray89": (227, 227, 227),
"gray90": (229, 229, 229),
"gray91": (232, 232, 232),
"gray92": (235, 235, 235),
"gray93": (237, 237, 237),
"gray94": (240, 240, 240),
"gray95": (242, 242, 242),
"gray96": (245, 245, 245),
"gray97": (247, 247, 247),
"gray98": (250, 250, 250),
"gray99": (252, 252, 252),
"gray100": (255, 255, 255),
"green": (0, 128, 0),
"green yellow": (173, 255, 47),
"green1": (0, 255, 0),
"green2": (0, 238, 0),
"green3": (0, 205, 0),
"green4": (0, 139, 0),
"greenyellow": (173, 255, 47),
"grey": (128, 128, 128),
"grey0": (0, 0, 0),
"grey1": (3, 3, 3),
"grey2": (5, 5, 5),
"grey3": (8, 8, 8),
"grey4": (10, 10, 10),
"grey5": (13, 13, 13),
"grey6": (15, 15, 15),
"grey7": (18, 18, 18),
"grey8": (20, 20, 20),
"grey9": (23, 23, 23),
"grey10": (26, 26, 26),
"grey11": (28, 28, 28),
"grey12": (31, 31, 31),
"grey13": (33, 33, 33),
"grey14": (36, 36, 36),
"grey15": (38, 38, 38),
"grey16": (41, 41, 41),
"grey17": (43, 43, 43),
"grey18": (46, 46, 46),
"grey19": (48, 48, 48),
"grey20": (51, 51, 51),
"grey21": (54, 54, 54),
"grey22": (56, 56, 56),
"grey23": (59, 59, 59),
"grey24": (61, 61, 61),
"grey25": (64, 64, 64),
"grey26": (66, 66, 66),
"grey27": (69, 69, 69),
"grey28": (71, 71, 71),
"grey29": (74, 74, 74),
"grey30": (77, 77, 77),
"grey31": (79, 79, 79),
"grey32": (82, 82, 82),
"grey33": (84, 84, 84),
"grey34": (87, 87, 87),
"grey35": (89, 89, 89),
"grey36": (92, 92, 92),
"grey37": (94, 94, 94),
"grey38": (97, 97, 97),
"grey39": (99, 99, 99),
"grey40": (102, 102, 102),
"grey41": (105, 105, 105),
"grey42": (107, 107, 107),
"grey43": (110, 110, 110),
"grey44": (112, 112, 112),
"grey45": (115, 115, 115),
"grey46": (117, 117, 117),
"grey47": (120, 120, 120),
"grey48": (122, 122, 122),
"grey49": (125, 125, 125),
"grey50": (127, 127, 127),
"grey51": (130, 130, 130),
"grey52": (133, 133, 133),
"grey53": (135, 135, 135),
"grey54": (138, 138, 138),
"grey55": (140, 140, 140),
"grey56": (143, 143, 143),
"grey57": (145, 145, 145),
"grey58": (148, 148, 148),
"grey59": (150, 150, 150),
"grey60": (153, 153, 153),
"grey61": (156, 156, 156),
"grey62": (158, 158, 158),
"grey63": (161, 161, 161),
"grey64": (163, 163, 163),
"grey65": (166, 166, 166),
"grey66": (168, 168, 168),
"grey67": (171, 171, 171),
"grey68": (173, 173, 173),
"grey69": (176, 176, 176),
"grey70": (179, 179, 179),
"grey71": (181, 181, 181),
"grey72": (184, 184, 184),
"grey73": (186, 186, 186),
"grey74": (189, 189, 189),
"grey75": (191, 191, 191),
"grey76": (194, 194, 194),
"grey77": (196, 196, 196),
"grey78": (199, 199, 199),
"grey79": (201, 201, 201),
"grey80": (204, 204, 204),
"grey81": (207, 207, 207),
"grey82": (209, 209, 209),
"grey83": (212, 212, 212),
"grey84": (214, 214, 214),
"grey85": (217, 217, 217),
"grey86": (219, 219, 219),
"grey87": (222, 222, 222),
"grey88": (224, 224, 224),
"grey89": (227, 227, 227),
"grey90": (229, 229, 229),
"grey91": (232, 232, 232),
"grey92": (235, 235, 235),
"grey93": (237, 237, 237),
"grey94": (240, 240, 240),
"grey95": (242, 242, 242),
"grey96": (245, 245, 245),
"grey97": (247, 247, 247),
"grey98": (250, 250, 250),
"grey99": (252, 252, 252),
"grey100": (255, 255, 255),
"honeydew": (240, 255, 240),
"honeydew1": (240, 255, 240),
"honeydew2": (224, 238, 224),
"honeydew3": (193, 205, 193),
"honeydew4": (131, 139, 131),
"hot pink": (255, 105, 180),
"hotpink": (255, 105, 180),
"hotpink1": (255, 110, 180),
"hotpink2": (238, 106, 167),
"hotpink3": (205, 96, 144),
"hotpink4": (139, 58, 98),
"indian red": (205, 92, 92),
"indianred": (205, 92, 92),
"indianred1": (255, 106, 106),
"indianred2": (238, 99, 99),
"indianred3": (205, 85, 85),
"indianred4": (139, 58, 58),
"indigo": (75, 0, 130),
"ivory": (255, 255, 240),
"ivory1": (255, 255, 240),
"ivory2": (238, 238, 224),
"ivory3": (205, 205, 193),
"ivory4": (139, 139, 131),
"khaki": (240, 230, 140),
"khaki1": (255, 246, 143),
"khaki2": (238, 230, 133),
"khaki3": (205, 198, 115),
"khaki4": (139, 134, 78),
"lavender": (230, 230, 250),
"lavender blush": (255, 240, 245),
"lavenderblush": (255, 240, 245),
"lavenderblush1": (255, 240, 245),
"lavenderblush2": (238, 224, 229),
"lavenderblush3": (205, 193, 197),
"lavenderblush4": (139, 131, 134),
"lawn green": (124, 252, 0),
"lawngreen": (124, 252, 0),
"lemon chiffon": (255, 250, 205),
"lemonchiffon": (255, 250, 205),
"lemonchiffon1": (255, 250, 205),
"lemonchiffon2": (238, 233, 191),
"lemonchiffon3": (205, 201, 165),
"lemonchiffon4": (139, 137, 112),
"light blue": (173, 216, 230),
"light coral": (240, 128, 128),
"light cyan": (224, 255, 255),
"light goldenrod": (238, 221, 130),
"light goldenrod yellow": (250, 250, 210),
"light gray": (211, 211, 211),
"light green": (144, 238, 144),
"light grey": (211, 211, 211),
"light pink": (255, 182, 193),
"light salmon": (255, 160, 122),
"light sea green": (32, 178, 170),
"light sky blue": (135, 206, 250),
"light slate blue": (132, 112, 255),
"light slate gray": (119, 136, 153),
"light slate grey": (119, 136, 153),
"light steel blue": (176, 196, 222),
"light yellow": (255, 255, 224),
"lightblue": (173, 216, 230),
"lightblue1": (191, 239, 255),
"lightblue2": (178, 223, 238),
"lightblue3": (154, 192, 205),
"lightblue4": (104, 131, 139),
"lightcoral": (240, 128, 128),
"lightcyan": (224, 255, 255),
"lightcyan1": (224, 255, 255),
"lightcyan2": (209, 238, 238),
"lightcyan3": (180, 205, 205),
"lightcyan4": (122, 139, 139),
"lightgoldenrod": (238, 221, 130),
"lightgoldenrod1": (255, 236, 139),
"lightgoldenrod2": (238, 220, 130),
"lightgoldenrod3": (205, 190, 112),
"lightgoldenrod4": (139, 129, 76),
"lightgoldenrodyellow": (250, 250, 210),
"lightgray": (211, 211, 211),
"lightgreen": (144, 238, 144),
"lightgrey": (211, 211, 211),
"lightpink": (255, 182, 193),
"lightpink1": (255, 174, 185),
"lightpink2": (238, 162, 173),
"lightpink3": (205, 140, 149),
"lightpink4": (139, 95, 101),
"lightsalmon": (255, 160, 122),
"lightsalmon1": (255, 160, 122),
"lightsalmon2": (238, 149, 114),
"lightsalmon3": (205, 129, 98),
"lightsalmon4": (139, 87, 66),
"lightseagreen": (32, 178, 170),
"lightskyblue": (135, 206, 250),
"lightskyblue1": (176, 226, 255),
"lightskyblue2": (164, 211, 238),
"lightskyblue3": (141, 182, 205),
"lightskyblue4": (96, 123, 139),
"lightslateblue": (132, 112, 255),
"lightslategray": (119, 136, 153),
"lightslategrey": (119, 136, 153),
"lightsteelblue": (176, 196, 222),
"lightsteelblue1": (202, 225, 255),
"lightsteelblue2": (188, 210, 238),
"lightsteelblue3": (162, 181, 205),
"lightsteelblue4": (110, 123, 139),
"lightyellow": (255, 255, 224),
"lightyellow1": (255, 255, 224),
"lightyellow2": (238, 238, 209),
"lightyellow3": (205, 205, 180),
"lightyellow4": (139, 139, 122),
"lime": (0, 255, 0),
"lime green": (50, 205, 50),
"limegreen": (50, 205, 50),
"linen": (250, 240, 230),
"magenta": (255, 0, 255),
"magenta1": (255, 0, 255),
"magenta2": (238, 0, 238),
"magenta3": (205, 0, 205),
"magenta4": (139, 0, 139),
"maroon": (128, 0, 0),
"maroon1": (255, 52, 179),
"maroon2": (238, 48, 167),
"maroon3": (205, 41, 144),
"maroon4": (139, 28, 98),
"medium aquamarine": (102, 205, 170),
"medium blue": (0, 0, 205),
"medium orchid": (186, 85, 211),
"medium purple": (147, 112, 219),
"medium sea green": (60, 179, 113),
"medium slate blue": (123, 104, 238),
"medium spring green": (0, 250, 154),
"medium turquoise": (72, 209, 204),
"medium violet red": (199, 21, 133),
"mediumaquamarine": (102, 205, 170),
"mediumblue": (0, 0, 205),
"mediumorchid": (186, 85, 211),
"mediumorchid1": (224, 102, 255),
"mediumorchid2": (209, 95, 238),
"mediumorchid3": (180, 82, 205),
"mediumorchid4": (122, 55, 139),
"mediumpurple": (147, 112, 219),
"mediumpurple1": (171, 130, 255),
"mediumpurple2": (159, 121, 238),
"mediumpurple3": (137, 104, 205),
"mediumpurple4": (93, 71, 139),
"mediumseagreen": (60, 179, 113),
"mediumslateblue": (123, 104, 238),
"mediumspringgreen": (0, 250, 154),
"mediumturquoise": (72, 209, 204),
"mediumvioletred": (199, 21, 133),
"midnight blue": (25, 25, 112),
"midnightblue": (25, 25, 112),
"mint cream": (245, 255, 250),
"mintcream": (245, 255, 250),
"misty rose": (255, 228, 225),
"mistyrose": (255, 228, 225),
"mistyrose1": (255, 228, 225),
"mistyrose2": (238, 213, 210),
"mistyrose3": (205, 183, 181),
"mistyrose4": (139, 125, 123),
"moccasin": (255, 228, 181),
"navajo white": (255, 222, 173),
"navajowhite": (255, 222, 173),
"navajowhite1": (255, 222, 173),
"navajowhite2": (238, 207, 161),
"navajowhite3": (205, 179, 139),
"navajowhite4": (139, 121, 94),
"navy": (0, 0, 128),
"navy blue": (0, 0, 128),
"navyblue": (0, 0, 128),
"old lace": (253, 245, 230),
"oldlace": (253, 245, 230),
"olive": (128, 128, 0),
"olive drab": (107, 142, 35),
"olivedrab": (107, 142, 35),
"olivedrab1": (192, 255, 62),
"olivedrab2": (179, 238, 58),
"olivedrab3": (154, 205, 50),
"olivedrab4": (105, 139, 34),
"orange": (255, 165, 0),
"orange red": (255, 69, 0),
"orange1": (255, 165, 0),
"orange2": (238, 154, 0),
"orange3": (205, 133, 0),
"orange4": (139, 90, 0),
"orangered": (255, 69, 0),
"orangered1": (255, 69, 0),
"orangered2": (238, 64, 0),
"orangered3": (205, 55, 0),
"orangered4": (139, 37, 0),
"orchid": (218, 112, 214),
"orchid1": (255, 131, 250),
"orchid2": (238, 122, 233),
"orchid3": (205, 105, 201),
"orchid4": (139, 71, 137),
"pale goldenrod": (238, 232, 170),
"pale green": (152, 251, 152),
"pale turquoise": (175, 238, 238),
"pale violet red": (219, 112, 147),
"palegoldenrod": (238, 232, 170),
"palegreen": (152, 251, 152),
"palegreen1": (154, 255, 154),
"palegreen2": (144, 238, 144),
"palegreen3": (124, 205, 124),
"palegreen4": (84, 139, 84),
"paleturquoise": (175, 238, 238),
"paleturquoise1": (187, 255, 255),
"paleturquoise2": (174, 238, 238),
"paleturquoise3": (150, 205, 205),
"paleturquoise4": (102, 139, 139),
"palevioletred": (219, 112, 147),
"palevioletred1": (255, 130, 171),
"palevioletred2": (238, 121, 159),
"palevioletred3": (205, 104, 127),
"palevioletred4": (139, 71, 93),
"papaya whip": (255, 239, 213),
"papayawhip": (255, 239, 213),
"peach puff": (255, 218, 185),
"peachpuff": (255, 218, 185),
"peachpuff1": (255, 218, 185),
"peachpuff2": (238, 203, 173),
"peachpuff3": (205, 175, 149),
"peachpuff4": (139, 119, 101),
"peru": (205, 133, 63),
"pink": (255, 192, 203),
"pink1": (255, 181, 197),
"pink2": (238, 169, 184),
"pink3": (205, 145, 158),
"pink4": (139, 99, 108),
"plum": (221, 160, 221),
"plum1": (255, 187, 255),
"plum2": (238, 174, 238),
"plum3": (205, 150, 205),
"plum4": (139, 102, 139),
"powder blue": (176, 224, 230),
"powderblue": (176, 224, 230),
"purple": (128, 0, 128),
"purple1": (155, 48, 255),
"purple2": (145, 44, 238),
"purple3": (125, 38, 205),
"purple4": (85, 26, 139),
"red": (255, 0, 0),
"red1": (255, 0, 0),
"red2": (238, 0, 0),
"red3": (205, 0, 0),
"red4": (139, 0, 0),
"rosy brown": (188, 143, 143),
"rosybrown": (188, 143, 143),
"rosybrown1": (255, 193, 193),
"rosybrown2": (238, 180, 180),
"rosybrown3": (205, 155, 155),
"rosybrown4": (139, 105, 105),
"royal blue": (65, 105, 225),
"royalblue": (65, 105, 225),
"royalblue1": (72, 118, 255),
"royalblue2": (67, 110, 238),
"royalblue3": (58, 95, 205),
"royalblue4": (39, 64, 139),
"saddle brown": (139, 69, 19),
"saddlebrown": (139, 69, 19),
"salmon": (250, 128, 114),
"salmon1": (255, 140, 105),
"salmon2": (238, 130, 98),
"salmon3": (205, 112, 84),
"salmon4": (139, 76, 57),
"sandy brown": (244, 164, 96),
"sandybrown": (244, 164, 96),
"sea green": (46, 139, 87),
"seagreen": (46, 139, 87),
"seagreen1": (84, 255, 159),
"seagreen2": (78, 238, 148),
"seagreen3": (67, 205, 128),
"seagreen4": (46, 139, 87),
"seashell": (255, 245, 238),
"seashell1": (255, 245, 238),
"seashell2": (238, 229, 222),
"seashell3": (205, 197, 191),
"seashell4": (139, 134, 130),
"sienna": (160, 82, 45),
"sienna1": (255, 130, 71),
"sienna2": (238, 121, 66),
"sienna3": (205, 104, 57),
"sienna4": (139, 71, 38),
"silver": (192, 192, 192),
"sky blue": (135, 206, 235),
"skyblue": (135, 206, 235),
"skyblue1": (135, 206, 255),
"skyblue2": (126, 192, 238),
"skyblue3": (108, 166, 205),
"skyblue4": (74, 112, 139),
"slate blue": (106, 90, 205),
"slate gray": (112, 128, 144),
"slate grey": (112, 128, 144),
"slateblue": (106, 90, 205),
"slateblue1": (131, 111, 255),
"slateblue2": (122, 103, 238),
"slateblue3": (105, 89, 205),
"slateblue4": (71, 60, 139),
"slategray": (112, 128, 144),
"slategray1": (198, 226, 255),
"slategray2": (185, 211, 238),
"slategray3": (159, 182, 205),
"slategray4": (108, 123, 139),
"slategrey": (112, 128, 144),
"snow": (255, 250, 250),
"snow1": (255, 250, 250),
"snow2": (238, 233, 233),
"snow3": (205, 201, 201),
"snow4": (139, 137, 137),
"spring green": (0, 255, 127),
"springgreen": (0, 255, 127),
"springgreen1": (0, 255, 127),
"springgreen2": (0, 238, 118),
"springgreen3": (0, 205, 102),
"springgreen4": (0, 139, 69),
"steel blue": (70, 130, 180),
"steelblue": (70, 130, 180),
"steelblue1": (99, 184, 255),
"steelblue2": (92, 172, 238),
"steelblue3": (79, 148, 205),
"steelblue4": (54, 100, 139),
"tan": (210, 180, 140),
"tan1": (255, 165, 79),
"tan2": (238, 154, 73),
"tan3": (205, 133, 63),
"tan4": (139, 90, 43),
"teal": (0, 128, 128),
"thistle": (216, 191, 216),
"thistle1": (255, 225, 255),
"thistle2": (238, 210, 238),
"thistle3": (205, 181, 205),
"thistle4": (139, 123, 139),
"tomato": (255, 99, 71),
"tomato1": (255, 99, 71),
"tomato2": (238, 92, 66),
"tomato3": (205, 79, 57),
"tomato4": (139, 54, 38),
"turquoise": (64, 224, 208),
"turquoise1": (0, 245, 255),
"turquoise2": (0, 229, 238),
"turquoise3": (0, 197, 205),
"turquoise4": (0, 134, 139),
"violet": (238, 130, 238),
"violet red": (208, 32, 144),
"violetred": (208, 32, 144),
"violetred1": (255, 62, 150),
"violetred2": (238, 58, 140),
"violetred3": (205, 50, 120),
"violetred4": (139, 34, 82),
"wheat": (245, 222, 179),
"wheat1": (255, 231, 186),
"wheat2": (238, 216, 174),
"wheat3": (205, 186, 150),
"wheat4": (139, 126, 102),
"white": (255, 255, 255),
"white smoke": (245, 245, 245),
"whitesmoke": (245, 245, 245),
"yellow": (255, 255, 0),
"yellow green": (154, 205, 50),
"yellow1": (255, 255, 0),
"yellow2": (238, 238, 0),
"yellow3": (205, 205, 0),
"yellow4": (139, 139, 0),
"yellowgreen": (154, 205, 50),
}
Mapping table for color names to RGB codes.
maliang.color.convert¶
字数 9 个 阅读时间不到 1 分钟 访问量
Convert a format of color to another format.
- RGB: tuple, (Red, Green, Blue)
- HSL: tuple, (Hue, Saturation, Lightness)
- RGBA: tuple, (Red, Green, Blue, Alpha)
- HEX: hexadecimal, such as ‘#ABCDEF’ or ‘#12345678‘
- NAME: string, such as ‘royalblue’
| 函数 | 描述 |
|---|---|
rgb_to_hex |
Convert a RGB code to a hexadecimal code. |
hex_to_rgb |
Convert a hexadecimal code to a RGB code. |
rgba_to_hex |
Convert a RGBA code to a hexadecimal code. |
hex_to_rgba |
Convert a hexadecimal code to a RGBA code. |
hsl_to_rgb |
Convert a HSL code to a RGB code. |
rgb_to_hsl |
Convert a RGB code to a HSL code. |
hsl_to_hex |
Convert a HSL code to a hexadecimal code. |
hex_to_hsl |
Convert a hexadecimal code to a HSL code. |
name_to_rgb |
Convert a color name to a RGB code. |
rgb_to_name |
Convert a RGB code to a color name. |
name_to_hex |
Convert a color name to a hexadecimal code. |
hex_to_name |
Convert a hexadecimal code to a color name. |
fix_hex_length |
Fix the length of a hexadecimal code. |
str_to_rgb |
Convert a color name or a hexadecimal code to a RGB code. |
rgb_to_hex
¶
hex_to_rgb
¶
rgba_to_hex
¶
hex_to_rgba
¶
rgb_to_rgba
¶
rgba_to_rgb
¶
hsl_to_rgb
¶
rgb_to_hsl
¶
hsl_to_hex
¶
hex_to_hsl
¶
name_to_rgb
¶
rgb_to_name
¶
name_to_hex
¶
hex_to_name
¶
fix_hex_length
¶
maliang.color.hsl¶
字数 9 个 阅读时间不到 1 分钟 访问量
Some functions about HSL codes.
| 函数 | 描述 |
|---|---|
contrast |
Get the contrasting color of a HSL code. |
transition |
Transition one color to another proportionally. |
blend |
Mix colors by weight. |
gradient |
Get a list of color gradients from one color to another proportionally. |
contrast
¶
transition
¶
transition(
first: tuple[float, float, float],
second: tuple[float, float, float],
rate: float,
*,
channels: tuple[bool, bool, bool] = (True, True, True),
) -> tuple[float, float, float]
blend
¶
gradient
¶
gradient(
first: tuple[float, float, float],
second: tuple[float, float, float],
count: int,
rate: float = 1,
*,
channels: tuple[bool, bool, bool] = (True, True, True),
controller: Callable[[float], float] = controllers.linear,
) -> list[tuple[float, float, float]]
Get a list of color gradients from one color to another proportionally.
| 参数 | 描述 |
|---|---|
|
the first HSL code. |
|
the second HSL code. |
|
the number of gradients.
类型:
|
|
transition rate.
类型:
|
|
three color channels. |
|
control function.
类型:
|
| 返回 | 描述 |
|---|---|
list[tuple[float, float, float]]
|
A list of color gradients. |
maliang.color.rgb¶
字数 9 个 阅读时间不到 1 分钟 访问量
Some functions about RGB codes.
| 函数 | 描述 |
|---|---|
contrast |
Get the contrasting color of a RGB code. |
transition |
Transition one color to another proportionally. |
blend |
Mix colors by weight. |
gradient |
Get a list of color gradients from one color to another proportionally. |
contrast
¶
transition
¶
transition(
first: tuple[int, int, int],
second: tuple[int, int, int],
rate: float,
*,
channels: tuple[bool, bool, bool] = (True, True, True),
) -> tuple[int, int, int]
blend
¶
gradient
¶
gradient(
first: tuple[int, int, int],
second: tuple[int, int, int],
count: int,
rate: float = 1,
*,
channels: tuple[bool, bool, bool] = (True, True, True),
controller: Callable[[float], float] = controllers.linear,
) -> list[tuple[int, int, int]]
Get a list of color gradients from one color to another proportionally.
| 参数 | 描述 |
|---|---|
|
the first RGB code. |
|
the second RGB code. |
|
the number of gradients.
类型:
|
|
transition rate.
类型:
|
|
three color channels. |
|
control function, default is linear.
类型:
|
| 返回 | 描述 |
|---|---|
list[tuple[int, int, int]]
|
A list of color gradients from the first RGB code to the second RGB code. |
core
maliang.core¶
字数 11 个 阅读时间不到 1 分钟 访问量
The core code, you can see the general framework here.
Most of the abstract and base classes are defined here.
| 模块 | 描述 |
|---|---|
configs |
All global configuration options. |
containers |
All containers. |
virtual |
All virtual classes. |
| CLASS | 描述 |
|---|---|
Env |
Configurations for default environment values. |
Font |
Configurations for default font. |
Constant |
All Constants. |
Tk |
Main window. |
Toplevel |
Toplevel window. |
Canvas |
Main contrainer: Canvas. |
| 函数 | 描述 |
|---|---|
reset |
Reset all configuration options. |
Env
¶
Configurations for default environment values.
| 属性 | 描述 |
|---|---|
system |
The system of environment, such as
TYPE:
|
theme |
The theme of the application.
TYPE:
|
gradient_animation |
Whether to enable gradient animation for widgets that support it by default.
TYPE:
|
auto_update |
Whether to check for updates automatically on startup.
TYPE:
|
root |
The current default root window. It is READ-ONLY. |
| 方法 | 描述 |
|---|---|
reset |
Reset all configuration options. |
get_default_system |
Get the system of environment. |
Font
¶
Constant
¶
All Constants.
| 属性 | 描述 |
|---|---|
GOLDEN_RATIO |
The golden ratio, which is needed to automatically calculate the color |
PREDEFINED_EVENTS |
Predefined events that can be used directly without registration. It is |
PREDEFINED_VIRTUAL_EVENTS |
Predefined virtual events that can be used directly without |
GOLDEN_RATIO
class-attribute
instance-attribute
¶
The golden ratio, which is needed to automatically calculate the color
of widget on "disabled" state. It is READ-ONLY.
PREDEFINED_EVENTS
class-attribute
instance-attribute
¶
PREDEFINED_EVENTS: Final[tuple[str, ...]] = (
"<KeyPress>",
"<KeyRelease>",
"<Button-1>",
"<Button-2>",
"<Button-3>",
"<Button-4>",
"<Button-5>",
"<ButtonRelease-1>",
"<ButtonRelease-2>",
"<ButtonRelease-3>",
"<MouseWheel>",
"<Motion>",
"<B1-Motion>",
"<B2-Motion>",
"<B3-Motion>",
"<Configure>",
)
Predefined events that can be used directly without registration. It is READ-ONLY.
Tk
¶
Tk(
size: tuple[int, int] = (1280, 720),
position: tuple[int, int] | None = None,
*,
title: str | None = None,
icon: str | enhanced.PhotoImage | None = None,
**kwargs: Any,
)
Main window.
In general, there is only one main window. But after destroying it, another one can be created.
| 属性 | 描述 |
|---|---|
light |
the color theme of light mode. |
dark |
the color theme of dark mode. |
| 参数 | 描述 |
|---|---|
|
size of the window. |
|
position of the window, based on the upper left corner. And negative numbers are based on the bottom right corner. |
|
title of the window, default value is
类型:
|
|
icon of the window, default value is the icon of tk.
类型:
|
|
additional keyword arguments for
类型:
|
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the window. |
geometry |
Change the size and position of the window and return the current |
center |
Center the container. |
icon |
Set the icon of the window. |
alpha |
Set or get the transparency of the window. |
topmost |
Set or get whether the window is pinned or not. |
fullscreen |
Set or get whether the window is full-screen. |
toolwindow |
Set or get whether the window is tool-window. |
transparentcolor |
Set or get the penetration color of the window. |
modified |
Set or get whether the window is modified. |
transparent |
Set or get whether the window is transparent. |
destroy |
Destroy the object. |
at_exit |
Set a function that will be called when the window is closed. |
theme
¶
theme(
value: Literal["light", "dark"], *, include_children: bool = True, include_canvases: bool = True
) -> None
geometry
¶
geometry(
*, size: tuple[int, int] | None = None, position: tuple[int, int] | None = None
) -> tuple[int, int, int, int] | None
Change the size and position of the window and return the current size and position of the window.
| 参数 | 描述 |
|---|---|
|
the size of the window, if it is |
|
the position of the window, if it is |
| 返回 | 描述 |
|---|---|
tuple[int, int, int, int] | None
|
The current size and position of the window if |
Note
If you want to use tkinter.Tk.geometry, please use
tkinter.Tk.wm_geometry instead.
center
¶
icon
¶
icon(value: str | enhanced.PhotoImage) -> None
Set the icon of the window.
| 参数 | 描述 |
|---|---|
|
the icon.
类型:
|
alpha
¶
topmost
¶
fullscreen
¶
Set or get whether the window is full-screen.
| 参数 | 描述 |
|---|---|
|
indicate whether the window is full-screen.
类型:
|
| 返回 | 描述 |
|---|---|
bool | None
|
The current full-screen state of the window if |
Note
The method should be called at the end of the code, or after some time after the program has started.
toolwindow
¶
transparentcolor
¶
modified
¶
transparent
¶
Toplevel
¶
Toplevel(
master: Tk | Toplevel | None = None,
size: tuple[int, int] = (960, 540),
position: tuple[int, int] | None = None,
*,
title: str | None = None,
icon: str | enhanced.PhotoImage | None = None,
grab: bool = False,
focus: bool = True,
**kwargs: Any,
)
Bases: tkinter.Toplevel, Tk, Misc
Toplevel window.
It can be used as a pop-up window, or it can be customized to put anything you want to show.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
size of the window, default value is 960x540(px). |
|
position of the window, default value indicates random. |
|
title of window, default is the same as title of master.
类型:
|
|
icon of the window, default is the same as title of master.
类型:
|
|
whether to grab the window.
类型:
|
|
whether direct input focus to this window.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
destroy |
Destroy the object. |
Canvas
¶
Canvas(
master: Tk | Toplevel | Canvas | None = None,
*,
expand: Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: Literal["min", "max"] | None = None,
free_anchor: bool = False,
auto_update: bool | None = None,
zoom_all_items: bool = False,
**kwargs: Any,
)
Main contrainer: Canvas.
The parent widget of all virtual widgets is Canvas.
| 属性 | 描述 |
|---|---|
light |
light theme colors. |
dark |
dark theme colors. |
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Canvas and its items. |
zoom |
Resize and position the |
destroy |
Destroy the object. |
clear |
Clear all things in the Canvas. |
on_motion |
Events to move the mouse. |
on_click |
Events to active the mouse. |
on_release |
Events to release the mouse. |
on_wheel |
Events to scroll the mouse wheel. |
on_key_press |
Events for typing. |
on_key_release |
Events for typing. |
register_event |
Register a event to process. |
hide_focus |
Hide the focus rectangle. |
theme
¶
zoom
¶
Resize and position the Canvas based on the relevant parameters.
This method only works for Canvas with Place layout.
on_wheel
¶
Events to scroll the mouse wheel.
maliang.core.configs¶
字数 9 个 阅读时间不到 1 分钟 访问量
All global configuration options.
Some options are read-only, but most of them can be changed, and once changed, they will take effect globally for the program. Some changes take effect immediately, but some need to take effect when the relevant option is invoked.
| CLASS | 描述 |
|---|---|
Env |
Configurations for default environment values. |
Font |
Configurations for default font. |
Constant |
All Constants. |
| 函数 | 描述 |
|---|---|
reset |
Reset all configuration options. |
Env
¶
Configurations for default environment values.
| 属性 | 描述 |
|---|---|
system |
The system of environment, such as
TYPE:
|
theme |
The theme of the application.
TYPE:
|
gradient_animation |
Whether to enable gradient animation for widgets that support it by default.
TYPE:
|
auto_update |
Whether to check for updates automatically on startup.
TYPE:
|
root |
The current default root window. It is READ-ONLY. |
| 方法 | 描述 |
|---|---|
reset |
Reset all configuration options. |
get_default_system |
Get the system of environment. |
Font
¶
Constant
¶
All Constants.
| 属性 | 描述 |
|---|---|
GOLDEN_RATIO |
The golden ratio, which is needed to automatically calculate the color |
PREDEFINED_EVENTS |
Predefined events that can be used directly without registration. It is |
PREDEFINED_VIRTUAL_EVENTS |
Predefined virtual events that can be used directly without |
GOLDEN_RATIO
class-attribute
instance-attribute
¶
The golden ratio, which is needed to automatically calculate the color
of widget on "disabled" state. It is READ-ONLY.
PREDEFINED_EVENTS
class-attribute
instance-attribute
¶
PREDEFINED_EVENTS: Final[tuple[str, ...]] = (
"<KeyPress>",
"<KeyRelease>",
"<Button-1>",
"<Button-2>",
"<Button-3>",
"<Button-4>",
"<Button-5>",
"<ButtonRelease-1>",
"<ButtonRelease-2>",
"<ButtonRelease-3>",
"<MouseWheel>",
"<Motion>",
"<B1-Motion>",
"<B2-Motion>",
"<B3-Motion>",
"<Configure>",
)
Predefined events that can be used directly without registration. It is READ-ONLY.
maliang.core.containers¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/core/containers.py
All containers.
There are two containers at the window level: Tk and Toplevel. Tk is
generally used for the main window, while Toplevel is a pop-up window.
There is another container at the canvas level: Canvas. Canvas is the
main container carrier.
| CLASS | 描述 |
|---|---|
Tk |
Main window. |
Toplevel |
Toplevel window. |
Canvas |
Main contrainer: Canvas. |
Misc
¶
Tk
¶
Tk(
size: tuple[int, int] = (1280, 720),
position: tuple[int, int] | None = None,
*,
title: str | None = None,
icon: str | enhanced.PhotoImage | None = None,
**kwargs: Any,
)
Main window.
In general, there is only one main window. But after destroying it, another one can be created.
| 属性 | 描述 |
|---|---|
light |
the color theme of light mode. |
dark |
the color theme of dark mode. |
| 参数 | 描述 |
|---|---|
|
size of the window. |
|
position of the window, based on the upper left corner. And negative numbers are based on the bottom right corner. |
|
title of the window, default value is
类型:
|
|
icon of the window, default value is the icon of tk.
类型:
|
|
additional keyword arguments for
类型:
|
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the window. |
geometry |
Change the size and position of the window and return the current |
center |
Center the container. |
icon |
Set the icon of the window. |
alpha |
Set or get the transparency of the window. |
topmost |
Set or get whether the window is pinned or not. |
fullscreen |
Set or get whether the window is full-screen. |
toolwindow |
Set or get whether the window is tool-window. |
transparentcolor |
Set or get the penetration color of the window. |
modified |
Set or get whether the window is modified. |
transparent |
Set or get whether the window is transparent. |
destroy |
Destroy the object. |
at_exit |
Set a function that will be called when the window is closed. |
theme
¶
theme(
value: Literal["light", "dark"], *, include_children: bool = True, include_canvases: bool = True
) -> None
geometry
¶
geometry(
*, size: tuple[int, int] | None = None, position: tuple[int, int] | None = None
) -> tuple[int, int, int, int] | None
Change the size and position of the window and return the current size and position of the window.
| 参数 | 描述 |
|---|---|
|
the size of the window, if it is |
|
the position of the window, if it is |
| 返回 | 描述 |
|---|---|
tuple[int, int, int, int] | None
|
The current size and position of the window if |
Note
If you want to use tkinter.Tk.geometry, please use
tkinter.Tk.wm_geometry instead.
center
¶
icon
¶
icon(value: str | enhanced.PhotoImage) -> None
Set the icon of the window.
| 参数 | 描述 |
|---|---|
|
the icon.
类型:
|
alpha
¶
topmost
¶
fullscreen
¶
Set or get whether the window is full-screen.
| 参数 | 描述 |
|---|---|
|
indicate whether the window is full-screen.
类型:
|
| 返回 | 描述 |
|---|---|
bool | None
|
The current full-screen state of the window if |
Note
The method should be called at the end of the code, or after some time after the program has started.
toolwindow
¶
transparentcolor
¶
modified
¶
transparent
¶
Toplevel
¶
Toplevel(
master: Tk | Toplevel | None = None,
size: tuple[int, int] = (960, 540),
position: tuple[int, int] | None = None,
*,
title: str | None = None,
icon: str | enhanced.PhotoImage | None = None,
grab: bool = False,
focus: bool = True,
**kwargs: Any,
)
Bases: tkinter.Toplevel, Tk, Misc
Toplevel window.
It can be used as a pop-up window, or it can be customized to put anything you want to show.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
size of the window, default value is 960x540(px). |
|
position of the window, default value indicates random. |
|
title of window, default is the same as title of master.
类型:
|
|
icon of the window, default is the same as title of master.
类型:
|
|
whether to grab the window.
类型:
|
|
whether direct input focus to this window.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
destroy |
Destroy the object. |
Canvas
¶
Canvas(
master: Tk | Toplevel | Canvas | None = None,
*,
expand: Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: Literal["min", "max"] | None = None,
free_anchor: bool = False,
auto_update: bool | None = None,
zoom_all_items: bool = False,
**kwargs: Any,
)
Main contrainer: Canvas.
The parent widget of all virtual widgets is Canvas.
| 属性 | 描述 |
|---|---|
light |
light theme colors. |
dark |
dark theme colors. |
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Canvas and its items. |
zoom |
Resize and position the |
destroy |
Destroy the object. |
clear |
Clear all things in the Canvas. |
on_motion |
Events to move the mouse. |
on_click |
Events to active the mouse. |
on_release |
Events to release the mouse. |
on_wheel |
Events to scroll the mouse wheel. |
on_key_press |
Events for typing. |
on_key_release |
Events for typing. |
register_event |
Register a event to process. |
hide_focus |
Hide the focus rectangle. |
theme
¶
zoom
¶
Resize and position the Canvas based on the relevant parameters.
This method only works for Canvas with Place layout.
on_wheel
¶
Events to scroll the mouse wheel.
maliang.core.virtual¶
字数 9 个 阅读时间不到 1 分钟 访问量
All virtual classes.
The virtual.Widget consists of five parts, which are Shape, Text,
Image, Style and Feature. In addition, they can be nested within
each other.
Where Feature is the function of widgets, Style control the color of the
widget, and each widget can be bound to up to one Feature and one Style,
but in terms of appearance, there is no limit to the number of Shape,
Text, and Image.
Shape, Text, and Image are all appearance elements that inherit from
abstract base class Elements.
| CLASS | 描述 |
|---|---|
Element |
The basic visible part of a |
Shape |
The Shape of a |
Text |
The Text of a |
Image |
The Image of a |
Style |
The styles of a |
Feature |
The features of a |
Widget |
Base Widget Class. |
Element
¶
Element(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs: Any,
)
The basic visible part of a virtual.Widget.
| 参数 | 描述 |
|---|---|
|
parent widget.
类型:
|
|
position relative to its widgets. |
|
size of element. |
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for element.
类型:
|
| 方法 | 描述 |
|---|---|
move |
Move the |
moveto |
Move the |
destroy |
Destroy the |
center |
Return the geometric center of the |
region |
Return the decision region of the |
detect |
Detect whether the specified coordinates are within |
update |
Update the style of the |
configure |
Configure properties of |
forget |
Let the element to forget. |
zoom |
Zoom the |
display |
Display the |
coords |
Resize the |
move
¶
moveto
¶
detect
¶
update
¶
update(state: str | None = None, *, gradient_animation: bool = False) -> None
configure
¶
forget
¶
forget(value: bool = True, *, gradient_animation: bool = False) -> None
zoom
¶
Shape
¶
Shape(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs: Any,
)
Text
¶
Text(
widget: Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
text: str = "",
limit: int = -1,
show: str | None = None,
placeholder: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Bases: Element
The Text of a Widget.
| 参数 | 描述 |
|---|---|
|
parent widget.
类型:
|
|
position relative to its widgets. |
|
size of element. |
|
text value.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the font.
类型:
|
|
slant of the font.
类型:
|
|
whether text is underline.
类型:
|
|
whether text is overstrike.
类型:
|
|
limit on the number of characters.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
a placeholder for the prompt.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
region |
Return the decision region of the |
zoom |
Scale the text. |
zoom
¶
Image
¶
Image(
widget: Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
image: enhanced.PhotoImage | None = None,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Bases: Element
The Image of a Widget.
| 参数 | 描述 |
|---|---|
|
parent widget.
类型:
|
|
position relative to its widgets. |
|
size of element. |
|
image object of the element.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
region |
Return the decision region of the |
zoom |
Scale the image. |
zoom
¶
Style
¶
Style(widget: Widget, *, auto_update: bool | None = None)
The styles of a Widget.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
style data of light theme. |
dark |
style data of dark theme. |
| 参数 | 描述 |
|---|---|
|
parent widget.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
| 方法 | 描述 |
|---|---|
get_disabled_style |
Get the style data of disabled state. |
init |
Initialize some style of an element. |
get |
Return the style of the widget. |
reset |
Reset the style of the widget and update. |
detach |
Detach the style data from the class data. |
set |
Set the style of the widget. |
Feature
¶
Widget
¶
Widget(
master: containers.Canvas | Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
anchor: Literal["n", "s", "w", "e", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_resize: bool | None = None,
auto_update: bool | None = None,
style: type[Style] | None = None,
)
Base Widget Class.
Widget = Element + Style + Feature
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
layout anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable animation.
类型:
|
|
whether to automatically resize after modifying the content of the widget.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
register_elements |
Register elements to the widget. |
deregister_elements |
Deregister a element from the widget. |
update |
Update the widget. |
bind_on_update |
Bind an extra function to the widget on update. |
unbind_on_update |
Unbind an extra function to the widget on update. |
bind |
Bind to this widget at event sequence a call to function command. |
unbind |
Unbind for this widget the event sequence. |
generate_event |
Generate an event sequence. Additional keyword arguments specify |
disable |
Disable the widget. |
forget |
Let all elements of the widget to forget. |
lift |
Lift the widget to the top. |
move |
Move the widget. |
moveto |
Move the Widget to a certain position. |
destroy |
Destroy the widget. |
exists |
Check if the widget exists. |
region |
Return the decision region of the |
detect |
Detect whether the specified coordinates are within the |
center |
Return the center of the widget. |
zoom |
Zoom widget ifself. |
resize |
Resize the widget. |
| 属性 | 描述 |
|---|---|
elements |
All elements of the widget. |
children |
All child widgets of the widget. |
nested |
Whether the widget is a nested widget.
TYPE:
|
offset |
The offset of the anchor relative to “nw”. |
register_elements
¶
deregister_elements
¶
update
¶
bind_on_update
¶
Bind an extra function to the widget on update.
This extra function has two positional arguments, both of which are
arguments to the method update. And this extra function will be
called when the widget is updated (whether it’s automatically updated
or manually updated).
| 参数 | 描述 |
|---|---|
|
the extra function that is bound. |
unbind_on_update
¶
bind
¶
bind(
sequence: str,
command: Callable[[tkinter.Event], Any],
add: bool | Literal["", "+"] | None = None,
*,
auto_detect: bool = True,
) -> None
Bind to this widget at event sequence a call to function command.
| 参数 | 描述 |
|---|---|
|
event name
类型:
|
|
callback function |
|
if True, original callback function will not be overwritten |
|
Automatically determine whether to execute binding
events based on the method
类型:
|
unbind
¶
generate_event
¶
disable
¶
forget
¶
move
¶
moveto
¶
detect
¶
media
maliang.media¶
字数 11 个 阅读时间不到 1 分钟 访问量
Extension package of maliang to play media files
Provides:
- The ability to play videos with audio;
| 模块 | 描述 |
|---|---|
icons |
All icons with base64 format |
main |
APIs for playing videos |
| CLASS | 描述 |
|---|---|
VideoCanvas |
A canvas that is scalable and playable for videos |
VideoCanvas
¶
VideoCanvas(
master: containers.Tk | containers.Toplevel | containers.Canvas | None = None,
*,
controls: bool = False,
loop: bool = False,
click_pause: bool = True,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: typing.Literal["min", "max"] | None = None,
free_anchor: bool = False,
**kwargs,
)
Bases: containers.Canvas
A canvas that is scalable and playable for videos
master: parent widgetcontrols: whether to enable the built-in UIloop: whether the video loops automaticallyclick_pause: whether to pause when clickedexpand: the mode of expand,xis horizontal, andyis verticalauto_zoom: whether or not to scale its itemskeep_ratio: the mode of aspect ratio,minfollows the minimum value,maxfollows the maximum valuefree_anchor: whether the anchor point is free-floatingkwargs: compatible with other parameters of classtkinter.Canvas
| 方法 | 描述 |
|---|---|
zoom |
Resize and position the |
open |
Open a video file and play |
close |
Close the video player |
destroy |
Destroy the object. |
maliang.media.icons¶
字数 9 个 阅读时间不到 1 分钟 访问量
All icons with base64 format
| 函数 | 描述 |
|---|---|
parse |
Parse the base64 data to |
maliang.media.main¶
字数 9 个 阅读时间不到 1 分钟 访问量
APIs for playing videos
| CLASS | 描述 |
|---|---|
VideoCanvas |
A canvas that is scalable and playable for videos |
VideoCanvas
¶
VideoCanvas(
master: containers.Tk | containers.Toplevel | containers.Canvas | None = None,
*,
controls: bool = False,
loop: bool = False,
click_pause: bool = True,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: typing.Literal["min", "max"] | None = None,
free_anchor: bool = False,
**kwargs,
)
Bases: containers.Canvas
A canvas that is scalable and playable for videos
master: parent widgetcontrols: whether to enable the built-in UIloop: whether the video loops automaticallyclick_pause: whether to pause when clickedexpand: the mode of expand,xis horizontal, andyis verticalauto_zoom: whether or not to scale its itemskeep_ratio: the mode of aspect ratio,minfollows the minimum value,maxfollows the maximum valuefree_anchor: whether the anchor point is free-floatingkwargs: compatible with other parameters of classtkinter.Canvas
| 方法 | 描述 |
|---|---|
zoom |
Resize and position the |
open |
Open a video file and play |
close |
Close the video player |
destroy |
Destroy the object. |
mpl
maliang.mpl¶
字数 11 个 阅读时间不到 1 分钟 访问量
Extension package of maliang for matplotlib
Provides:
- Implemented an easy-to-use
matplotlibinterface totkinter - Themed drawing experience
- Good interaction with
matplotlibplottings
| 模块 | 描述 |
|---|---|
constants |
Constants for theme |
main |
APIs for Matplotlib |
| CLASS | 描述 |
|---|---|
FigureCanvas |
A canvas for interface of |
FigureToolbar |
An interface class for the matplotlib navigation cursor |
| 函数 | 描述 |
|---|---|
set_mpl_default_theme |
Set default color constants of |
FigureCanvas
¶
Bases: tkinter.Canvas, matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
A canvas for interface of matplotlib
master: parent widgetfigure: aFigureobject frommatplotlib
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Figure. |
FigureToolbar
¶
FigureToolbar(
master: tkinter.Misc | FigureCanvas,
figure_canvas: FigureCanvas | None = None,
*,
pack_toolbar: bool = True,
**kwargs,
)
Bases: matplotlib.backends._backend_tk.NavigationToolbar2Tk
An interface class for the matplotlib navigation cursor
master: parent widgetfigure_canvas: the figure canvas on which to operatepack_toolbar: if True, add the toolbar to the parent’s pack manager’s packing list during initialization withside="bottom"andfill="x".
If you want to use the toolbar with a different layout manager,
use pack_toolbar=False
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Toolbar. |
maliang.mpl.constants¶
字数 9 个 阅读时间不到 1 分钟 访问量
maliang.mpl.main¶
字数 9 个 阅读时间不到 1 分钟 访问量
APIs for Matplotlib
| CLASS | 描述 |
|---|---|
FigureCanvas |
A canvas for interface of |
FigureToolbar |
An interface class for the matplotlib navigation cursor |
| 函数 | 描述 |
|---|---|
set_mpl_default_theme |
Set default color constants of |
FigureCanvas
¶
Bases: tkinter.Canvas, matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
A canvas for interface of matplotlib
master: parent widgetfigure: aFigureobject frommatplotlib
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Figure. |
FigureToolbar
¶
FigureToolbar(
master: tkinter.Misc | FigureCanvas,
figure_canvas: FigureCanvas | None = None,
*,
pack_toolbar: bool = True,
**kwargs,
)
Bases: matplotlib.backends._backend_tk.NavigationToolbar2Tk
An interface class for the matplotlib navigation cursor
master: parent widgetfigure_canvas: the figure canvas on which to operatepack_toolbar: if True, add the toolbar to the parent’s pack manager’s packing list during initialization withside="bottom"andfill="x".
If you want to use the toolbar with a different layout manager,
use pack_toolbar=False
| 方法 | 描述 |
|---|---|
theme |
Change the color theme of the Toolbar. |
standard
maliang.standard¶
字数 11 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/__init__.py
All standard things.
| 模块 | 描述 |
|---|---|
dialogs |
All standard dialog classes. |
features |
All standard |
images |
All standard |
shapes |
All standard |
styles |
All standard |
texts |
All standard |
widgets |
All standard |
| CLASS | 描述 |
|---|---|
TkMessage |
Message pop-up. |
TkColorChooser |
Color chooser pop-up. |
TkFontChooser |
Font chooser pop-up. |
Text |
Text widget, generally used to display plain text. |
Image |
Image widget, generally used to display normal still image. |
Label |
Label widget, which is generally used to display key information. |
Button |
Button widget, typically used to trigger a function. |
Switch |
Switch widget, typically used to control the turning of a function on |
InputBox |
Input box widget, generally used to enter certain information on a single |
CheckBox |
Checkbox button widget, generally used to check some options. |
ToggleButton |
A button that can display information and switch statuses. |
RadioBox |
Radio button widget, generally used to select one of several options. |
ProgressBar |
Progress bar widget, typically used to show the progress of an event. |
UnderlineButton |
Underline button, generally used to display web links. |
HighlightButton |
Highlight button, no outline, which added a highlight effect. |
IconButton |
A button with an icon on the left side. |
Slider |
A slider for visually resizing values. |
SegmentedButton |
A segmented button that can be used to toggle between multiple states. |
SpinBox |
A widget that makes it easy to enter numeric type data. |
OptionButton |
A button that has many options to choose. |
ComboBox |
An input box that can provide several options. |
Spinner |
Spinners visually communicate that something is processing. |
Tooltip |
A tooltip that can display additional information. |
TkMessage
¶
TkMessage(
message: str | None = None,
detail: str | None = None,
*,
title: str | None = None,
icon: Literal["error", "info", "question", "warning"] = "info",
option: Literal[
"abortretryignore", "ok", "okcancel", "retrycancel", "yesno", "yesnocancel"
] = "ok",
default: Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"] | None = None,
master: tkinter.Tk | None = None,
command: Callable[[Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"]], Any]
| None = None,
)
Message pop-up.
| 参数 | 描述 |
|---|---|
|
message.
类型:
|
|
detail message.
类型:
|
|
title of the window.
类型:
|
|
icon.
类型:
|
|
type of the message pop-up.
类型:
|
|
button where the focus is, default is the leftmost one.
类型:
|
|
parent widget. |
|
callback function.
类型:
|
TkColorChooser
¶
TkFontChooser
¶
Text
¶
Text(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
wrap_length: int | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Text widget, generally used to display plain text.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
limit the length of text, beyond which it will automatically wrap.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Image
¶
Image(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Image widget, generally used to display normal still image.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the image of the widget. |
set |
Set the image of the widget. |
Label
¶
Label(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Label widget, which is generally used to display key information.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Button
¶
Button(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Button widget, typically used to trigger a function.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Switch
¶
Switch(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 60,
*,
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Switch widget, typically used to control the turning of a function on and off.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the switch is changed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the switch. |
set |
Set the state of the switch. |
InputBox
¶
InputBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
align: Literal["left", "right", "center"] = "left",
placeholder: str = "",
show: str | None = None,
ignore: tuple[str, ...] = ("\n", "\r"),
limit: int = -1,
limit_width: int = 0,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Input box widget, generally used to enter certain information on a single line.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
ignore the input of some characters. |
|
a placeholder for the prompt.
类型:
|
|
limit on the number of characters.
类型:
|
|
limit on the width of characters.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the value of the Entry. |
set |
Set the text value of the Entry. |
insert |
Insert. |
append |
Append text to Entry. |
remove |
Remove. |
pop |
Delete a specified amount of text. |
clear |
Clear the text value of the Entry. |
update |
Update the widget. |
CheckBox
¶
CheckBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 30,
*,
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Checkbox button widget, generally used to check some options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of check button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the check button. |
set |
Set the state of the check button. |
ToggleButton
¶
ToggleButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button that can display information and switch statuses.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of check button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the check button. |
set |
Set the state of the switch. |
RadioBox
¶
RadioBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 30,
*,
default: bool | None = None,
command: Callable[[int], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Radio button widget, generally used to select one of several options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of radio button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the radio button. |
set |
Set the state of the radio button. |
group |
Combine other radio boxes. |
ProgressBar
¶
ProgressBar(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (400, 20),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Progress bar widget, typically used to show the progress of an event.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget
类型:
|
|
a function that is triggered when the progress of progress bar is 100%. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the progress of the progress bar. |
set |
Set the progress of the progress bar. |
UnderlineButton
¶
UnderlineButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool = False,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Underline button, generally used to display web links.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the underline button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
HighlightButton
¶
HighlightButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Highlight button, no outline, which added a highlight effect.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the hightlight button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
IconButton
¶
IconButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button with an icon on the left side.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Slider
¶
Slider(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (400, 30),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A slider for visually resizing values.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the value of the slider. |
set |
Set the value of the slider. |
SegmentedButton
¶
SegmentedButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
sizes: tuple[tuple[int, int], ...] = (),
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
layout: Literal["horizontal", "vertical"] = "horizontal",
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A segmented button that can be used to toggle between multiple states.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
layout mode of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
SpinBox
¶
SpinBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
format_spec: str = "d",
step: float = 1,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
align: Literal["left", "right", "center"] = "left",
placeholder: str = "",
show: str | None = None,
limit: int = math.inf,
default: str | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A widget that makes it easy to enter numeric type data.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
format of value.
类型:
|
|
value of each change.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
a placeholder for the prompt.
类型:
|
|
limit on the number of characters. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
change |
Try change the current value. |
get |
Get the value of the Entry. |
set |
Set the text value of the Entry. |
append |
Append text to Entry. |
delete |
Delete a specified amount of text. |
clear |
Clear the text value of the Entry. |
OptionButton
¶
OptionButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
align: Literal["up", "center", "down"] = "center",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button that has many options to choose.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
align of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
ComboBox
¶
ComboBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
align: Literal["up", "down"] = "down",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
An input box that can provide several options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
align of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
Spinner
¶
Spinner(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (30, 30),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
widths: tuple[int, int] | None = None,
mode: Literal["determinate", "indeterminate"] = "determinate",
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Spinners visually communicate that something is processing.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the progress of progress bar is 100%. |
|
width of the outside ring and inside ring. |
|
mode of the Spinner.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the progress of the Spinner. |
set |
Set the progress of the Spinner. |
destroy |
Destroy the widget. |
Tooltip
¶
Tooltip(
widget: virtual.Widget,
size: tuple[int, int] | None = None,
*,
text: str = "",
align: Literal["up", "down", "right", "left", "center"] = "down",
padding: int = 3,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A tooltip that can display additional information.
| 参数 | 描述 |
|---|---|
|
the associated widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
align mode of the tooltip.
类型:
|
|
extra padding between tooltip and the associated widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
maliang.standard.dialogs¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/dialogs.py
All standard dialog classes.
| CLASS | 描述 |
|---|---|
TkMessage |
Message pop-up. |
TkColorChooser |
Color chooser pop-up. |
TkFontChooser |
Font chooser pop-up. |
TkMessage
¶
TkMessage(
message: str | None = None,
detail: str | None = None,
*,
title: str | None = None,
icon: Literal["error", "info", "question", "warning"] = "info",
option: Literal[
"abortretryignore", "ok", "okcancel", "retrycancel", "yesno", "yesnocancel"
] = "ok",
default: Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"] | None = None,
master: tkinter.Tk | None = None,
command: Callable[[Literal["abort", "retry", "ignore", "ok", "cancel", "yes", "no"]], Any]
| None = None,
)
Message pop-up.
| 参数 | 描述 |
|---|---|
|
message.
类型:
|
|
detail message.
类型:
|
|
title of the window.
类型:
|
|
icon.
类型:
|
|
type of the message pop-up.
类型:
|
|
button where the focus is, default is the leftmost one.
类型:
|
|
parent widget. |
|
callback function.
类型:
|
TkColorChooser
¶
maliang.standard.features¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/features.py
All standard Feature classes.
| CLASS | 描述 |
|---|---|
TextFeature |
Feature of Text. |
ImageFeature |
Feature of Image. |
LabelFeature |
Feature of Label. |
ButtonFeature |
Feature of Button. |
Underline |
Feature of underline. |
Highlight |
Feature of highlight. |
SwitchFeature |
Feature of Switch. |
ToggleButtonFeature |
Feature of ToggleButton. |
CheckBoxFeature |
Feature of CheckButton. |
RadioBoxFeature |
Feature of RadioButton. |
ProgressBarFeature |
Feature of ProgressBar. |
InputBoxFeature |
Feature of input box. |
SliderFeature |
Feature of Slider. |
SegmentedButtonFeature |
Feature of SegmentedButton. |
SpinBoxFeature |
Feature of SpinBox. |
maliang.standard.images¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/images.py
All standard Image classes.
| CLASS | 描述 |
|---|---|
StillImage |
A simple still image. |
StillImage
¶
StillImage(
widget: Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
image: enhanced.PhotoImage | None = None,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Smoke
¶
Smoke(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
color: str | None = "#00000066",
name: str | None = None,
animation: bool = True,
**kwargs: Any,
)
A special Image with only one color.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
color of the image object of the element.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 引发 | 描述 |
|---|---|
RuntimeError
|
If the |
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
maliang.standard.shapes¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/shapes.py
All standard Shape classes.
| CLASS | 描述 |
|---|---|
Line |
Create a line for a widget. |
Rectangle |
Create a rectangle for a widget. |
Oval |
Create a oval for a widget |
Arc |
Create a arc for a widget. |
RegularPolygon |
Create a regular polygon for a widget. |
RoundedRectangle |
Create a rounded rectangle for a widget. |
HalfRoundedRectangle |
Create a half rounded rectangle for a widget. |
SemicircularRectangle |
Create a semicircular rectangle for a widget. |
SharpRectangle |
Create a sharp rectangle for a widget. |
Parallelogram |
Create a parallelogram for a widget. |
Line
¶
Line(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
points: list[tuple[float, float]] | None = None,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Create a line for a widget.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
key points of line. |
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
Rectangle
¶
Rectangle(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs: Any,
)
Oval
¶
Oval(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs: Any,
)
Arc
¶
Arc(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs: Any,
)
RegularPolygon
¶
RegularPolygon(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
side: int = 3,
angle: float = 0,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Create a regular polygon for a widget.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
number of sides of a regular polygon.
类型:
|
|
number of radians of a regular polygon rotated clockwise.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
RoundedRectangle
¶
RoundedRectangle(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
radius: int = 5,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Create a rounded rectangle for a widget.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
radius of the fillet.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
HalfRoundedRectangle
¶
HalfRoundedRectangle(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
radius: int = 5,
ignore: Literal["left", "right"] = "left",
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Create a half rounded rectangle for a widget.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
radius of the fillet.
类型:
|
|
edges to ignore.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
SemicircularRectangle
¶
SemicircularRectangle(
widget: Widget,
position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
name: str | None = None,
gradient_animation: bool | None = None,
**kwargs: Any,
)
SharpRectangle
¶
SharpRectangle(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
theta: float = math.pi / 6,
ratio: tuple[float, float] = (0.5, 0.5),
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Create a sharp rectangle for a widget.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
number of radians of sharp corners. |
|
height ratio of the left and right sharp corners. |
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
Parallelogram
¶
Parallelogram(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
theta: float = math.pi / 6,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Create a parallelogram for a widget.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
number of radians that the parallelogram is inclined to. |
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
maliang.standard.styles¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/styles.py
All standard Style classes.
| CLASS | 描述 |
|---|---|
TextStyle |
Style of Text. |
LabelStyle |
Style of Label. |
ButtonStyle |
Style of Button. |
SwitchStyle |
Style of Switch. |
InputBoxStyle |
Style of InputBox. |
ToggleButtonStyle |
Style of ToggleButton. |
CheckBoxStyle |
Style of CheckBox. |
RadioBoxStyle |
Style of RadioGroup. |
ProgressBarStyle |
Style of ProgressBar. |
UnderlineButtonStyle |
Style of UnderlineButton. |
HighlightButtonStyle |
Style of HighlightButtonStyle. |
IconButtonStyle |
Style of IconButtonStyle. |
SliderStyle |
Style of Slider. |
SegmentedButtonStyle |
Style of SegmentedButton. |
OptionButtonStyle |
Style of OptionButton. |
SpinnerStyle |
Style of Spinner. |
TooltipStyle |
Style of Tooltip. |
TextStyle
¶
TextStyle(widget: Widget, *, auto_update: bool | None = None)
Style of Text.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
LabelStyle
¶
LabelStyle(widget: Widget, *, auto_update: bool | None = None)
Style of Label.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg: str | tuple[str | types.EllipsisType, ...] | None = None,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover"
| 参数 | 描述 |
|---|---|
|
The theme to apply the style to.
类型:
|
|
The foreground color of the widget.
类型:
|
|
The background color of the widget.
类型:
|
|
The outline color of the widget.
类型:
|
ButtonStyle
¶
ButtonStyle(widget: Widget, *, auto_update: bool | None = None)
Bases: LabelStyle
Style of Button.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg: str | tuple[str | types.EllipsisType, ...] | None = None,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover", "active"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the foreground color of the widget.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
SwitchStyle
¶
SwitchStyle(widget: Widget, *, auto_update: bool | None = None)
Style of Switch.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
bg_slot: str | tuple[str | types.EllipsisType, ...] | None = None,
ol_slot: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_dot: str | tuple[str | types.EllipsisType, ...] | None = None,
ol_dot: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal-off", "hover-off", "active-off",
"normal-on", "hover-on", "active-on"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
|
the inside background color of the widget.
类型:
|
|
the inside outline color of the widget.
类型:
|
InputBoxStyle
¶
InputBoxStyle(widget: Widget, *, auto_update: bool | None = None)
Style of InputBox.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg: str | tuple[str | types.EllipsisType, ...] | None = None,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_bar: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover", "active"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the foreground color of the widget.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
|
the highlight bar of the widget (Only for Windows11 theme).
类型:
|
ToggleButtonStyle
¶
ToggleButtonStyle(widget: Widget, *, auto_update: bool | None = None)
Style of ToggleButton.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg: str | tuple[str | types.EllipsisType, ...] | None = None,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal-off", "hover-off", "active-off",
"normal-on", "hover-on", "active-on"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the foreground color of the widget.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
CheckBoxStyle
¶
CheckBoxStyle(widget: Widget, *, auto_update: bool | None = None)
RadioBoxStyle
¶
RadioBoxStyle(widget: Widget, *, auto_update: bool | None = None)
Style of RadioGroup.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
bg_box: str | tuple[str | types.EllipsisType, ...] | None = None,
ol_box: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_dot: str | tuple[str | types.EllipsisType, ...] | None = None,
ol_dot: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover", "active"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
|
the inside background color of the widget.
类型:
|
|
the inside outline color of the widget.
类型:
|
ProgressBarStyle
¶
ProgressBarStyle(widget: Widget, *, auto_update: bool | None = None)
Style of ProgressBar.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
bg_slot: str | tuple[str | types.EllipsisType, ...] | None = None,
ol_slot: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_bar: str | tuple[str | types.EllipsisType, ...] | None = None,
ol_bar: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
|
the inside background color of the widget.
类型:
|
|
the inside outline color of the widget.
类型:
|
UnderlineButtonStyle
¶
UnderlineButtonStyle(widget: Widget, *, auto_update: bool | None = None)
HighlightButtonStyle
¶
HighlightButtonStyle(widget: Widget, *, auto_update: bool | None = None)
IconButtonStyle
¶
IconButtonStyle(widget: Widget, *, auto_update: bool | None = None)
SliderStyle
¶
SliderStyle(widget: Widget, *, auto_update: bool | None = None)
Style of Slider.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg_slot: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_slot: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_pnt: str | tuple[str | types.EllipsisType, ...] | None = None,
bg_dot: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover", "active"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the foreground color of the widget.
类型:
|
|
the background color of the widget.
类型:
|
|
the pointer color of the widget.
类型:
|
|
the pointer highlight part color of the widget (Only for Windows11 theme).
类型:
|
SegmentedButtonStyle
¶
SegmentedButtonStyle(widget: Widget, *, auto_update: bool | None = None)
Style of SegmentedButton.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
ToggleButtonStyle4SB
¶
ToggleButtonStyle4SB(widget: Widget, *, auto_update: bool | None = None)
OptionButtonStyle
¶
OptionButtonStyle(widget: Widget, *, auto_update: bool | None = None)
Style of OptionButton.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal", "hover", "active"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
SpinnerStyle
¶
SpinnerStyle(widget: Widget, *, auto_update: bool | None = None)
Style of Spinner.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg: str | tuple[str | types.EllipsisType, ...] | None = None,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the foreground color of the widget.
类型:
|
|
the background color of the widget.
类型:
|
TooltipStyle
¶
TooltipStyle(widget: Widget, *, auto_update: bool | None = None)
Style of Tooltip.
| 属性 | 描述 |
|---|---|
states |
all states of the widget. |
light |
The light theme style dictionary. |
dark |
The dark theme style dictionary. |
| 方法 | 描述 |
|---|---|
set |
Set the style of the widget. |
set
¶
set(
theme: Literal["light", "dark"] | None = None,
*,
fg: str | tuple[str | types.EllipsisType, ...] | None = None,
bg: str | tuple[str | types.EllipsisType, ...] | None = None,
ol: str | tuple[str | types.EllipsisType, ...] | None = None,
) -> None
Set the style of the widget.
states: "normal"
| 参数 | 描述 |
|---|---|
|
the theme name, None indicates both.
类型:
|
|
the foreground color of the widget.
类型:
|
|
the background color of the widget.
类型:
|
|
the outline color of the widget.
类型:
|
maliang.standard.texts¶
字数 9 个 阅读时间不到 1 分钟 访问量
All standard Text classes.
| CLASS | 描述 |
|---|---|
Information |
General information text. |
SingleLineText |
Single-line editable text. |
Information
¶
Information(
widget: Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
text: str = "",
limit: int = -1,
show: str | None = None,
placeholder: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
General information text.
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
get |
Get the value of |
set |
Set the value of |
append |
Append value to the value of |
delete |
Remove a portion of the |
clear |
Clear the value of |
SingleLineText
¶
SingleLineText(
widget: virtual.Widget,
relative_position: tuple[int, int] = (0, 0),
size: tuple[int, int] | None = None,
*,
text: str = "",
ignore: str | tuple[str, ...] = "\n\r",
limit: int = -1,
limit_width: int = 0,
show: str | None = None,
placeholder: str = "",
align: Literal["left", "center", "right"] = "left",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
name: str | None = None,
gradient_animation: bool = True,
**kwargs: Any,
)
Single-line editable text.
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
position relative to its widgets. |
|
size of element. |
|
text value.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the font.
类型:
|
|
slant of the font.
类型:
|
|
whether text is underline.
类型:
|
|
whether text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
ignore the input of some characters. |
|
limit on the number of characters.
类型:
|
|
limit on the width of characters.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
a placeholder for the prompt.
类型:
|
|
name of element.
类型:
|
|
whether use animation to change color.
类型:
|
|
extra parameters for CanvasItem.
类型:
|
| 方法 | 描述 |
|---|---|
display |
Display the |
coords |
Resize the |
get |
Get text of the element. |
set |
Set text of the element. |
insert |
Insert text to the location of the specified index. |
append |
Add some characters to the text cursor. |
remove |
Remove text within the specified index range. |
pop |
Delete a character at the text cursor. |
clear |
Clear. |
cursor_move |
Move the index position of the text cursor. |
cursor_move_to |
Move the index position of the text cursor to a certain index. |
maliang.standard.widgets¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/standard/widgets.py
All standard Widget classes.
| CLASS | 描述 |
|---|---|
Text |
Text widget, generally used to display plain text. |
Image |
Image widget, generally used to display normal still image. |
Label |
Label widget, which is generally used to display key information. |
Button |
Button widget, typically used to trigger a function. |
Switch |
Switch widget, typically used to control the turning of a function on |
InputBox |
Input box widget, generally used to enter certain information on a single |
CheckBox |
Checkbox button widget, generally used to check some options. |
ToggleButton |
A button that can display information and switch statuses. |
RadioBox |
Radio button widget, generally used to select one of several options. |
ProgressBar |
Progress bar widget, typically used to show the progress of an event. |
UnderlineButton |
Underline button, generally used to display web links. |
HighlightButton |
Highlight button, no outline, which added a highlight effect. |
IconButton |
A button with an icon on the left side. |
Slider |
A slider for visually resizing values. |
SegmentedButton |
A segmented button that can be used to toggle between multiple states. |
SpinBox |
A widget that makes it easy to enter numeric type data. |
OptionButton |
A button that has many options to choose. |
ComboBox |
An input box that can provide several options. |
Spinner |
Spinners visually communicate that something is processing. |
Tooltip |
A tooltip that can display additional information. |
Text
¶
Text(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
wrap_length: int | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Text widget, generally used to display plain text.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
limit the length of text, beyond which it will automatically wrap.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Image
¶
Image(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Image widget, generally used to display normal still image.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the image of the widget. |
set |
Set the image of the widget. |
Label
¶
Label(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Label widget, which is generally used to display key information.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Button
¶
Button(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Button widget, typically used to trigger a function.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Switch
¶
Switch(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 60,
*,
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Switch widget, typically used to control the turning of a function on and off.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the switch is changed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the switch. |
set |
Set the state of the switch. |
InputBox
¶
InputBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
align: Literal["left", "right", "center"] = "left",
placeholder: str = "",
show: str | None = None,
ignore: tuple[str, ...] = ("\n", "\r"),
limit: int = -1,
limit_width: int = 0,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Input box widget, generally used to enter certain information on a single line.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
ignore the input of some characters. |
|
a placeholder for the prompt.
类型:
|
|
limit on the number of characters.
类型:
|
|
limit on the width of characters.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the value of the Entry. |
set |
Set the text value of the Entry. |
insert |
Insert. |
append |
Append text to Entry. |
remove |
Remove. |
pop |
Delete a specified amount of text. |
clear |
Clear the text value of the Entry. |
update |
Update the widget. |
CheckBox
¶
CheckBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 30,
*,
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Checkbox button widget, generally used to check some options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of check button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the check button. |
set |
Set the state of the check button. |
ToggleButton
¶
ToggleButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: bool | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button that can display information and switch statuses.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of check button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the check button. |
set |
Set the state of the switch. |
RadioBox
¶
RadioBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
length: int = 30,
*,
default: bool | None = None,
command: Callable[[int], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Radio button widget, generally used to select one of several options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
length of the widget.
类型:
|
|
default state of the widget.
类型:
|
|
a function that is triggered when the state of radio button is on. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the state of the radio button. |
set |
Set the state of the radio button. |
group |
Combine other radio boxes. |
ProgressBar
¶
ProgressBar(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (400, 20),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Progress bar widget, typically used to show the progress of an event.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget
类型:
|
|
a function that is triggered when the progress of progress bar is 100%. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the progress of the progress bar. |
set |
Set the progress of the progress bar. |
UnderlineButton
¶
UnderlineButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool = False,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Underline button, generally used to display web links.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the underline button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
HighlightButton
¶
HighlightButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Highlight button, no outline, which added a highlight effect.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the hightlight button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
IconButton
¶
IconButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: str = "",
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
command: Callable | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button with an icon on the left side.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
a function that is triggered when the button is pressed.
类型:
|
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
Slider
¶
Slider(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (400, 30),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A slider for visually resizing values.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the value of the slider. |
set |
Set the value of the slider. |
SegmentedButton
¶
SegmentedButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
sizes: tuple[tuple[int, int], ...] = (),
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
layout: Literal["horizontal", "vertical"] = "horizontal",
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A segmented button that can be used to toggle between multiple states.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
layout mode of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
SpinBox
¶
SpinBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
format_spec: str = "d",
step: float = 1,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
align: Literal["left", "right", "center"] = "left",
placeholder: str = "",
show: str | None = None,
limit: int = math.inf,
default: str | None = None,
command: Callable[[bool], Any] | None = None,
image: enhanced.PhotoImage | None = None,
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A widget that makes it easy to enter numeric type data.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
format of value.
类型:
|
|
value of each change.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
align mode of the text.
类型:
|
|
display a value that obscures the original content.
类型:
|
|
a placeholder for the prompt.
类型:
|
|
limit on the number of characters. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
change |
Try change the current value. |
get |
Get the value of the Entry. |
set |
Set the text value of the Entry. |
append |
Append text to Entry. |
delete |
Delete a specified amount of text. |
clear |
Clear the text value of the Entry. |
OptionButton
¶
OptionButton(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
align: Literal["up", "center", "down"] = "center",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A button that has many options to choose.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
align of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
ComboBox
¶
ComboBox(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] | None = None,
*,
text: tuple[str, ...] = (),
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
default: int | None = None,
command: Callable[[int | None], Any] | None = None,
image: tuple[enhanced.PhotoImage | None, ...] = (),
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
align: Literal["up", "down"] = "down",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
An input box that can provide several options.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
text of the widget. |
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
default value of the widget.
类型:
|
|
a function that is triggered when the button is pressed. |
|
image of the widget.
类型:
|
|
anchor of the widget.
类型:
|
|
align of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the index of the child toggle button with a value of True. If |
set |
Activate the child toggle button for the specified index. |
Spinner
¶
Spinner(
master: containers.Canvas | virtual.Widget,
position: tuple[int, int],
size: tuple[int, int] = (30, 30),
*,
default: float | None = None,
command: Callable[[float], Any] | None = None,
widths: tuple[int, int] | None = None,
mode: Literal["determinate", "indeterminate"] = "determinate",
anchor: Literal["n", "e", "w", "s", "nw", "ne", "sw", "se", "center"] = "nw",
capture_events: bool | None = None,
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
Spinners visually communicate that something is processing.
| 参数 | 描述 |
|---|---|
|
parent canvas.
类型:
|
|
position of the widget. |
|
size of the widget. |
|
default value of the widget.
类型:
|
|
a function that is triggered when the progress of progress bar is 100%. |
|
width of the outside ring and inside ring. |
|
mode of the Spinner.
类型:
|
|
anchor of the widget.
类型:
|
|
whether detect another widget under the widget.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the progress of the Spinner. |
set |
Set the progress of the Spinner. |
destroy |
Destroy the widget. |
Tooltip
¶
Tooltip(
widget: virtual.Widget,
size: tuple[int, int] | None = None,
*,
text: str = "",
align: Literal["up", "down", "right", "left", "center"] = "down",
padding: int = 3,
family: str | None = None,
fontsize: int | None = None,
weight: Literal["normal", "bold"] = "normal",
slant: Literal["roman", "italic"] = "roman",
underline: bool = False,
overstrike: bool = False,
justify: Literal["left", "center", "right"] = "left",
gradient_animation: bool | None = None,
auto_update: bool | None = None,
style: type[virtual.Style] | None = None,
)
A tooltip that can display additional information.
| 参数 | 描述 |
|---|---|
|
the associated widget. |
|
size of the widget. |
|
text of the widget.
类型:
|
|
align mode of the tooltip.
类型:
|
|
extra padding between tooltip and the associated widget.
类型:
|
|
font family.
类型:
|
|
font size.
类型:
|
|
weight of the text.
类型:
|
|
slant of the text.
类型:
|
|
whether the text is underline.
类型:
|
|
whether the text is overstrike.
类型:
|
|
justify mode of the text.
类型:
|
|
whether enable gradient_animation.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
style of the widget. |
| 方法 | 描述 |
|---|---|
get |
Get the text of the widget. |
set |
Set the text of the widget. |
table
maliang.table¶
字数 11 个 阅读时间不到 1 分钟 访问量
maliang.table.constants¶
字数 9 个 阅读时间不到 1 分钟 访问量
maliang.table.main¶
字数 9 个 阅读时间不到 1 分钟 访问量
APIs for tksheet
| CLASS | 描述 |
|---|---|
TkTable |
A tkinter widget for displaying a table. |
theme
maliang.theme¶
字数 11 个 阅读时间不到 1 分钟 访问量
A subpackage that provides theme-related features.
Listen to the system’s theme and respond accordingly, modify the style of the window, and more.
| 模块 | 描述 |
|---|---|
manager |
Support for theme. |
| 函数 | 描述 |
|---|---|
set_color_mode |
Set the color mode of the program. |
get_color_mode |
Get the color mode of the program. |
register_event |
Register a function to be called when the system accent color changes. |
remove_event |
Remove a registered function. |
apply_file_dnd |
Apply file drag and drop in a widget. |
apply_theme |
Apply some Windows themes to the window. |
customize_window |
Customize the relevant properties of the window |
set_color_mode
¶
register_event
¶
Register a function to be called when the system accent color changes.
When the system accent color changes, the registered function will be called, and the parameter is a boolean value indicating whether it is currently a dark theme.
| 参数 | 描述 |
|---|---|
|
callback function. |
|
extra arguments.
类型:
|
remove_event
¶
apply_file_dnd
¶
apply_theme
¶
apply_theme(
window: tkinter.Tk,
*,
theme: Literal[
"mica",
"acrylic",
"acrylic2",
"aero",
"transparent",
"optimised",
"win7",
"inverse",
"native",
"popup",
"dark",
"normal",
],
) -> None
Apply some Windows themes to the window.
| 参数 | 描述 |
|---|---|
|
the window which being customized. |
|
different themes for windows.
类型:
|
Warning
This function is only works on Windows OS! And some parameters are useless on Windows 7/10!
customize_window
¶
customize_window(
window: tkinter.Tk,
*,
border_color: str | None = None,
header_color: str | None = None,
title_color: str | None = None,
hide_title_bar: bool | None = None,
hide_button: Literal["all", "maxmin", "none"] | None = None,
disable_minimize_button: bool | None = None,
disable_maximize_button: bool | None = None,
border_type: Literal["rectangular", "smallround", "round"] | None = None,
) -> None
Customize the relevant properties of the window
| 参数 | 描述 |
|---|---|
|
the window which being customized. |
|
border color of the window.
类型:
|
|
header color of the window.
类型:
|
|
title color of the window.
类型:
|
|
whether hide the whole title bar.
类型:
|
|
whether hide part of buttons on title bar.
类型:
|
|
whether disable minimize button.
类型:
|
|
whether disable maximize button.
类型:
|
|
border type of the window.
类型:
|
Warning
This function is only works on Windows OS! And some parameters are useless on Windows 7/10!
maliang.theme.manager¶
字数 9 个 阅读时间不到 1 分钟 访问量
Support for theme.
darkdetect: pypi.org/project/darkdetect/pywinstyles: pypi.org/project/pywinstyles/win32material: pypi.org/project/win32material/hPyT: pypi.org/project/hPyT/
| 函数 | 描述 |
|---|---|
set_color_mode |
Set the color mode of the program. |
get_color_mode |
Get the color mode of the program. |
register_event |
Register a function to be called when the system accent color changes. |
remove_event |
Remove a registered function. |
apply_file_dnd |
Apply file drag and drop in a widget. |
apply_theme |
Apply some Windows themes to the window. |
customize_window |
Customize the relevant properties of the window |
set_color_mode
¶
register_event
¶
Register a function to be called when the system accent color changes.
When the system accent color changes, the registered function will be called, and the parameter is a boolean value indicating whether it is currently a dark theme.
| 参数 | 描述 |
|---|---|
|
callback function. |
|
extra arguments.
类型:
|
remove_event
¶
apply_file_dnd
¶
apply_theme
¶
apply_theme(
window: tkinter.Tk,
*,
theme: Literal[
"mica",
"acrylic",
"acrylic2",
"aero",
"transparent",
"optimised",
"win7",
"inverse",
"native",
"popup",
"dark",
"normal",
],
) -> None
Apply some Windows themes to the window.
| 参数 | 描述 |
|---|---|
|
the window which being customized. |
|
different themes for windows.
类型:
|
Warning
This function is only works on Windows OS! And some parameters are useless on Windows 7/10!
customize_window
¶
customize_window(
window: tkinter.Tk,
*,
border_color: str | None = None,
header_color: str | None = None,
title_color: str | None = None,
hide_title_bar: bool | None = None,
hide_button: Literal["all", "maxmin", "none"] | None = None,
disable_minimize_button: bool | None = None,
disable_maximize_button: bool | None = None,
border_type: Literal["rectangular", "smallround", "round"] | None = None,
) -> None
Customize the relevant properties of the window
| 参数 | 描述 |
|---|---|
|
the window which being customized. |
|
border color of the window.
类型:
|
|
header color of the window.
类型:
|
|
title color of the window.
类型:
|
|
whether hide the whole title bar.
类型:
|
|
whether hide part of buttons on title bar.
类型:
|
|
whether disable minimize button.
类型:
|
|
whether disable maximize button.
类型:
|
|
border type of the window.
类型:
|
Warning
This function is only works on Windows OS! And some parameters are useless on Windows 7/10!
three
maliang.three¶
字数 11 个 阅读时间不到 1 分钟 访问量
Extension package of maliang for simple 3D drawings
Provides:
- Pure 3D implementation with no third-party packages
- Simple 3D drawing and manipulation
- Themed 3D drawings
| 模块 | 描述 |
|---|---|
engine |
Core codes of 3D |
geometries |
Standard Geometries |
| CLASS | 描述 |
|---|---|
Canvas |
Base class of 3D Canvas |
Space |
A canvas where you can view 3D objects |
Component |
3D 对象基类 |
Point |
点 |
Line |
线 |
Plane |
面 |
Text3D |
三维文本 |
Geometry |
几何体 |
Cuboid |
Cuboid |
Tetrahedron |
Tetrahedron |
| 函数 | 描述 |
|---|---|
translate |
将一个三维空间中的点进行平移 |
rotate |
将一个三维空间中的点以一个点或线为参照进行旋转(实现方式为欧拉角) |
scale |
将一个三维空间中的点以另一个点为缩放中心进行缩放 |
project |
将一个三维空间中的点投影到指定距离的正向平面上,并返回在该平面上的坐标 |
Canvas
¶
Canvas(
master: containers.Tk | containers.Toplevel | containers.Canvas | None = None,
*,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: typing.Literal["min", "max"] | None = None,
free_anchor: bool = False,
**kwargs,
)
Bases: containers.Canvas
Base class of 3D Canvas
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
space_sort |
Sort the contextual relationship between the spatial positions of the components |
| 属性 | 描述 |
|---|---|
components |
Return all |
geometries |
Return all |
Space
¶
Space(
master: containers.Tk | containers.Toplevel | containers.Canvas | None = None,
*,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: typing.Literal["min", "max"] | None = None,
free_anchor: bool = False,
**kwargs,
)
Bases: Canvas
A canvas where you can view 3D objects
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
Component
¶
Component(*coordinates)
Point
¶
Point(
canvas,
coords,
*,
size=1,
width=1,
fill="#000000",
outline="#000000",
markuptext="",
markupdelta=(0, 0),
markupfont=(configs.Font.family, configs.Font.size),
markupfill="#000000",
markupjustify="center",
)
Plane
¶
Text3D
¶
Geometry
¶
几何体
canvas: 父画布sides: 组成几何体的面
| 方法 | 描述 |
|---|---|
translate |
平移几何体中的所有 3D 对象 |
rotate |
旋转几何体中的所有 3D 对象 |
scale |
缩放几何体中的所有 3D 对象 |
center |
几何中心 |
update |
更新几何体 |
append |
给几何体添加更多新的面 |
Cuboid
¶
Cuboid(
canvas: engine.Canvas | engine.Space,
x: float,
y: float,
z: float,
length: float,
width: float,
height: float,
*,
boardwidth: int = 1,
color_fill_up: str = "",
color_fill_down: str = "",
color_fill_left: str = "",
color_fill_right: str = "",
color_fill_front: str = "",
color_fill_back: str = "",
color_outline_up: str = "#000000",
color_outline_down: str = "#000000",
color_outline_left: str = "#000000",
color_outline_right: str = "#000000",
color_outline_front: str = "#000000",
color_outline_back: str = "#000000",
)
Tetrahedron
¶
Tetrahedron(
canvas: engine.Canvas | engine.Space,
point_1: tuple[float, float, float],
point_2: tuple[float, float, float],
point_3: tuple[float, float, float],
point_4: tuple[float, float, float],
*,
boardwidth: int = 1,
color_fill: tuple[str, str, str, str] = ("", "", "", ""),
color_outline: tuple[str, str, str, str] = ("#000000", "#000000", "#000000", "#000000"),
)
translate
¶
translate(
coordinate: tuple[float, float, float], dx: float = 0, dy: float = 0, dz: float = 0
) -> None
将一个三维空间中的点进行平移
coordinate: 点的空间坐标dx: x 方向位移长度dy: y 方向位移长度dz: z 方向位移长度
rotate
¶
rotate(coordinate, dx=0, dy=0, dz=0, *, center)
rotate(coordinate, dx=0, *, axis)
将一个三维空间中的点以一个点或线为参照进行旋转(实现方式为欧拉角)
coordinate: 点的空间坐标dx: x 方向逆时针旋转弧度,或者绕旋转轴线的旋转弧度dy: y 方向逆时针旋转弧度dz: z 方向逆时针旋转弧度center: 旋转中心的空间坐标axis: 旋转轴线的空间坐标
scale
¶
scale(coordinate, kx=1, ky=1, kz=1, *, center)
将一个三维空间中的点以另一个点为缩放中心进行缩放
coordinate: 点的空间坐标kx: x 方向缩放比例ky: y 方向缩放比例kz: z 方向缩放比例center: 缩放中心的空间坐标
project
¶
project(coordinate, distance)
将一个三维空间中的点投影到指定距离的正向平面上,并返回在该平面上的坐标
coordinate: 点的空间坐标distance: 正向平面的距离(平面正对着我们)
maliang.three.engine¶
字数 9 个 阅读时间不到 1 分钟 访问量
Core codes of 3D
| CLASS | 描述 |
|---|---|
Canvas |
Base class of 3D Canvas |
Space |
A canvas where you can view 3D objects |
Component |
3D 对象基类 |
Point |
点 |
Line |
线 |
Plane |
面 |
Text3D |
三维文本 |
Geometry |
几何体 |
| 函数 | 描述 |
|---|---|
translate |
将一个三维空间中的点进行平移 |
rotate |
将一个三维空间中的点以一个点或线为参照进行旋转(实现方式为欧拉角) |
scale |
将一个三维空间中的点以另一个点为缩放中心进行缩放 |
project |
将一个三维空间中的点投影到指定距离的正向平面上,并返回在该平面上的坐标 |
Canvas
¶
Canvas(
master: containers.Tk | containers.Toplevel | containers.Canvas | None = None,
*,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: typing.Literal["min", "max"] | None = None,
free_anchor: bool = False,
**kwargs,
)
Bases: containers.Canvas
Base class of 3D Canvas
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
| 方法 | 描述 |
|---|---|
space_sort |
Sort the contextual relationship between the spatial positions of the components |
| 属性 | 描述 |
|---|---|
components |
Return all |
geometries |
Return all |
Space
¶
Space(
master: containers.Tk | containers.Toplevel | containers.Canvas | None = None,
*,
expand: typing.Literal["", "x", "y", "xy"] = "xy",
auto_zoom: bool = False,
keep_ratio: typing.Literal["min", "max"] | None = None,
free_anchor: bool = False,
**kwargs,
)
Bases: Canvas
A canvas where you can view 3D objects
| 参数 | 描述 |
|---|---|
|
parent widget. |
|
the mode of expand,
类型:
|
|
whether or not to scale its items automatically.
类型:
|
|
the mode of aspect ratio,
类型:
|
|
whether the anchor point is free-floating.
类型:
|
|
whether the theme manager update it automatically.
类型:
|
|
whether or not to scale its allitems.
类型:
|
|
compatible with other parameters of class
类型:
|
Component
¶
Component(*coordinates)
Point
¶
Point(
canvas,
coords,
*,
size=1,
width=1,
fill="#000000",
outline="#000000",
markuptext="",
markupdelta=(0, 0),
markupfont=(configs.Font.family, configs.Font.size),
markupfill="#000000",
markupjustify="center",
)
Plane
¶
Text3D
¶
Geometry
¶
几何体
canvas: 父画布sides: 组成几何体的面
| 方法 | 描述 |
|---|---|
translate |
平移几何体中的所有 3D 对象 |
rotate |
旋转几何体中的所有 3D 对象 |
scale |
缩放几何体中的所有 3D 对象 |
center |
几何中心 |
update |
更新几何体 |
append |
给几何体添加更多新的面 |
translate
¶
translate(
coordinate: tuple[float, float, float], dx: float = 0, dy: float = 0, dz: float = 0
) -> None
将一个三维空间中的点进行平移
coordinate: 点的空间坐标dx: x 方向位移长度dy: y 方向位移长度dz: z 方向位移长度
rotate
¶
rotate(coordinate, dx=0, dy=0, dz=0, *, center)
rotate(coordinate, dx=0, *, axis)
将一个三维空间中的点以一个点或线为参照进行旋转(实现方式为欧拉角)
coordinate: 点的空间坐标dx: x 方向逆时针旋转弧度,或者绕旋转轴线的旋转弧度dy: y 方向逆时针旋转弧度dz: z 方向逆时针旋转弧度center: 旋转中心的空间坐标axis: 旋转轴线的空间坐标
scale
¶
scale(coordinate, kx=1, ky=1, kz=1, *, center)
将一个三维空间中的点以另一个点为缩放中心进行缩放
coordinate: 点的空间坐标kx: x 方向缩放比例ky: y 方向缩放比例kz: z 方向缩放比例center: 缩放中心的空间坐标
project
¶
project(coordinate, distance)
将一个三维空间中的点投影到指定距离的正向平面上,并返回在该平面上的坐标
coordinate: 点的空间坐标distance: 正向平面的距离(平面正对着我们)
maliang.three.geometries¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/three/geometries.py
Standard Geometries
| CLASS | 描述 |
|---|---|
Cuboid |
Cuboid |
Tetrahedron |
Tetrahedron |
Cuboid
¶
Cuboid(
canvas: engine.Canvas | engine.Space,
x: float,
y: float,
z: float,
length: float,
width: float,
height: float,
*,
boardwidth: int = 1,
color_fill_up: str = "",
color_fill_down: str = "",
color_fill_left: str = "",
color_fill_right: str = "",
color_fill_front: str = "",
color_fill_back: str = "",
color_outline_up: str = "#000000",
color_outline_down: str = "#000000",
color_outline_left: str = "#000000",
color_outline_right: str = "#000000",
color_outline_front: str = "#000000",
color_outline_back: str = "#000000",
)
Tetrahedron
¶
Tetrahedron(
canvas: engine.Canvas | engine.Space,
point_1: tuple[float, float, float],
point_2: tuple[float, float, float],
point_3: tuple[float, float, float],
point_4: tuple[float, float, float],
*,
boardwidth: int = 1,
color_fill: tuple[str, str, str, str] = ("", "", "", ""),
color_outline: tuple[str, str, str, str] = ("#000000", "#000000", "#000000", "#000000"),
)
toolbox
maliang.toolbox¶
字数 11 个 阅读时间不到 1 分钟 访问量
源代码:maliang/toolbox/__init__.py
Some practical tools.
| 模块 | 描述 |
|---|---|
enhanced |
Enhanced versions of some |
utility |
Some useful utility classes or utility functions. |
| CLASS | 描述 |
|---|---|
PhotoImage |
Pillow version of |
| 函数 | 描述 |
|---|---|
get_parent |
Get the HWND of |
embed_window |
Embed a widget into another widget. |
load_font |
Make fonts located in file |
screen_size |
Returns the size of the screen. |
get_text_size |
Get the size of a text with a special font family and font size. |
fix_cursor |
Fix the cursor name. |
create_smoke |
Create a temporary smoke zone. Return the |
PhotoImage
¶
Bases: ImageTk.PhotoImage, tkinter.PhotoImage
Pillow version of tkinter.PhotoImage.
| 方法 | 描述 |
|---|---|
scale |
Scale the PhotoImage. |
resize |
Resize the PhotoImage. |
get_parent
¶
embed_window
¶
load_font
¶
Make fonts located in file font_path available to the font system.
| 参数 | 描述 |
|---|---|
|
the font file path. |
|
if True, other processes cannot see this font(Only Windows OS), and this font will be unloaded when the process dies.
类型:
|
|
if True, this font will appear when enumerating fonts(Only Windows OS).
类型:
|
| 返回 | 描述 |
|---|---|
bool
|
Whether the operation succeeds. |
Warning
This function only works on Windows and Linux OS.
Note
This function is referenced from customtkinter.load_font,
customtkinter: TomSchimansky/CustomTkinter.
get_text_size
¶
get_text_size(
text: str,
fontsize: int | None = None,
family: str | None = None,
*,
padding: int = 0,
wrap_length: int | None = None,
font: tkinter.font.Font | None = None,
master: tkinter.Canvas | virtual.Widget | None = None,
**kwargs: Any,
) -> tuple[int, int]
Get the size of a text with a special font family and font size.
| 参数 | 描述 |
|---|---|
|
the text.
类型:
|
|
font size of the text.
类型:
|
|
font family of the text.
类型:
|
|
extra padding of the size.
类型:
|
|
limit the length of text, beyond which it will automatically wrap.
类型:
|
|
font object to use (if |
|
default canvas or widget provided. |
|
additional keyword arguments for the font.
类型:
|
Warning
This function only works when the fontsize is negative number!
fix_cursor
¶
create_smoke
¶
create_smoke(
size: tuple[int, int], *, color: str | tuple[int, int, int, int] = "#00000066"
) -> enhanced.PhotoImage
Create a temporary smoke zone. Return the enhanced.PhotoImage.
| 参数 | 描述 |
|---|---|
|
size of the smoke zone. |
|
color of the smoke zone. |
| 返回 | 描述 |
|---|---|
enhanced.PhotoImage
|
Enhanced photo image of the smoke zone. |
| 引发 | 描述 |
|---|---|
RuntimeError
|
If the |
Warning
This function need PIL to run.
Tip
About the “smoke”, see: fluent2.microsoft.design/material#smoke
maliang.toolbox.enhanced¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/toolbox/enhanced.py
Enhanced versions of some tkinter classes and functions.
| CLASS | 描述 |
|---|---|
PhotoImage |
Pillow version of |
PhotoImage
¶
Bases: ImageTk.PhotoImage, tkinter.PhotoImage
Pillow version of tkinter.PhotoImage.
| 方法 | 描述 |
|---|---|
scale |
Scale the PhotoImage. |
resize |
Resize the PhotoImage. |
maliang.toolbox.utility¶
字数 9 个 阅读时间不到 1 分钟 访问量
源代码:maliang/toolbox/utility.py
Some useful utility classes or utility functions.
| 函数 | 描述 |
|---|---|
get_parent |
Get the HWND of |
embed_window |
Embed a widget into another widget. |
load_font |
Make fonts located in file |
screen_size |
Returns the size of the screen. |
get_text_size |
Get the size of a text with a special font family and font size. |
fix_cursor |
Fix the cursor name. |
create_smoke |
Create a temporary smoke zone. Return the |
Trigger
¶
Single trigger.
It can only be triggered once before the reset, and multiple triggers are invalid. When triggered, the callback function is called.
| 参数 | 描述 |
|---|---|
|
the function that is called when triggered. |
| 方法 | 描述 |
|---|---|
get |
Get the status of the trigger. |
reset |
Reset the status of the trigger. |
lock |
Lock the trigger so that it can’t be updated. |
unlock |
Unlock this trigger so that it can be updated again. |
update |
Update the status of the trigger. |
get_parent
¶
embed_window
¶
load_font
¶
Make fonts located in file font_path available to the font system.
| 参数 | 描述 |
|---|---|
|
the font file path. |
|
if True, other processes cannot see this font(Only Windows OS), and this font will be unloaded when the process dies.
类型:
|
|
if True, this font will appear when enumerating fonts(Only Windows OS).
类型:
|
| 返回 | 描述 |
|---|---|
bool
|
Whether the operation succeeds. |
Warning
This function only works on Windows and Linux OS.
Note
This function is referenced from customtkinter.load_font,
customtkinter: TomSchimansky/CustomTkinter.
get_text_size
¶
get_text_size(
text: str,
fontsize: int | None = None,
family: str | None = None,
*,
padding: int = 0,
wrap_length: int | None = None,
font: tkinter.font.Font | None = None,
master: tkinter.Canvas | virtual.Widget | None = None,
**kwargs: Any,
) -> tuple[int, int]
Get the size of a text with a special font family and font size.
| 参数 | 描述 |
|---|---|
|
the text.
类型:
|
|
font size of the text.
类型:
|
|
font family of the text.
类型:
|
|
extra padding of the size.
类型:
|
|
limit the length of text, beyond which it will automatically wrap.
类型:
|
|
font object to use (if |
|
default canvas or widget provided. |
|
additional keyword arguments for the font.
类型:
|
Warning
This function only works when the fontsize is negative number!
fix_cursor
¶
create_smoke
¶
create_smoke(
size: tuple[int, int], *, color: str | tuple[int, int, int, int] = "#00000066"
) -> enhanced.PhotoImage
Create a temporary smoke zone. Return the enhanced.PhotoImage.
| 参数 | 描述 |
|---|---|
|
size of the smoke zone. |
|
color of the smoke zone. |
| 返回 | 描述 |
|---|---|
enhanced.PhotoImage
|
Enhanced photo image of the smoke zone. |
| 引发 | 描述 |
|---|---|
RuntimeError
|
If the |
Warning
This function need PIL to run.
Tip
About the “smoke”, see: fluent2.microsoft.design/material#smoke
实战教学
实战教学¶
字数 19 个 阅读时间不到 1 分钟 访问量
很遗憾呢
肥肠抱歉!还没有更新噢~





































































































